Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 29, 2024
1 parent 7ad18f5 commit 7076482
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 29 deletions.
29 changes: 15 additions & 14 deletions _test/test_block_seq_local_indent.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import io
from typing import Any, Dict, List, Text # NOQA

import pytest
import io
import ruyaml # NOQA
from .roundtrip import round_trip, dedent

import ruyaml # NOQA
from ruyaml import YAML
from ruyaml.util import load_yaml_guess_indent
from ruyaml.scalarbool import ScalarBoolean
from ruyaml.comments import CommentedSeq
from ruyaml.representer import RoundTripRepresenter, ScalarNode
from ruyaml.constructor import RoundTripConstructor
from typing import Text, Any, Dict, List # NOQA
from ruyaml.representer import RoundTripRepresenter, ScalarNode
from ruyaml.scalarbool import ScalarBoolean
from ruyaml.util import load_yaml_guess_indent

from .roundtrip import dedent, round_trip


class ScalarNodePositioned(ScalarNode):
lc_position = None


class ScalarBooleanStable(ScalarBoolean):

def __new__(cls: Any, boolval, origrepr, anchor=None) -> Any:
b = ScalarBoolean.__new__(cls, boolval, anchor=anchor)
b.original_bool_repr = origrepr
return b


#def represent_list2(self, data):
# def represent_list2(self, data):
# dedede
# RoundTripRepresenter.add_representer(CommentedSeq, represent_list2)

Expand All @@ -36,7 +36,9 @@ class BetterRoundTripConstructor(RoundTripConstructor):

class BetterRoundTripRepresenter(RoundTripRepresenter):
def represent_bool(self, data, anchor=None):
ret = self.represent_scalar('tag:yaml.org,2002:bool', data.original_bool_repr, anchor=anchor)
ret = self.represent_scalar(
'tag:yaml.org,2002:bool', data.original_bool_repr, anchor=anchor
)
return ret

def TOTO_represent_sequence(self, tag, data):
Expand All @@ -46,8 +48,8 @@ def TOTO_represent_sequence(self, tag, data):
local_block_seq_ident = -1


#BetterRoundTripConstructor.add_constructor('tag:yaml.org,2002:bool', BetterRoundTripConstructor.construct_yaml_bool)
#BetterRoundTripRepresenter.add_representer(ScalarBooleanStable, BetterRoundTripRepresenter.represent_bool)
# BetterRoundTripConstructor.add_constructor('tag:yaml.org,2002:bool', BetterRoundTripConstructor.construct_yaml_bool)
# BetterRoundTripRepresenter.add_representer(ScalarBooleanStable, BetterRoundTripRepresenter.represent_bool)


def round_trip_stabler(
Expand All @@ -68,7 +70,6 @@ def round_trip_stabler(


class TestStability:

def test_blockseq1(self):
round_trip(
"""
Expand Down Expand Up @@ -101,8 +102,8 @@ def test_blockseq3(self):
"""
)

class TestStabilityStabler:

class TestStabilityStabler:
def test_blockseq1(self):
round_trip_stabler(
"""
Expand Down
16 changes: 8 additions & 8 deletions _test/test_bools.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import io
from typing import Any, Dict, List, Text # NOQA

import pytest
import io
import ruyaml # NOQA
from .roundtrip import round_trip, dedent

import ruyaml # NOQA
from ruyaml import YAML
from ruyaml.util import load_yaml_guess_indent
from ruyaml.scalarbool import ScalarBoolean
from ruyaml.comments import CommentedSeq
from ruyaml.representer import RoundTripRepresenter, ScalarNode
from ruyaml.constructor import RoundTripConstructor
from typing import Text, Any, Dict, List # NOQA
from ruyaml.representer import RoundTripRepresenter, ScalarNode
from ruyaml.scalarbool import ScalarBoolean
from ruyaml.util import load_yaml_guess_indent

from .roundtrip import dedent, round_trip


def round_trip_stabler(
Expand All @@ -31,7 +32,6 @@ def round_trip_stabler(


class TestStability:

def test_lowercase_boolean(self):
round_trip(
"""
Expand Down
14 changes: 12 additions & 2 deletions lib/ruyaml/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def __init__(


class SequenceStartEvent(CollectionStartEvent):
__slots__ = ('block_seq_indent', )
__slots__ = ('block_seq_indent',)

def __init__(
self,
Expand All @@ -201,7 +201,17 @@ def __init__(
block_seq_indent=None,
):
# type: (Any, Any, Any, Any, Any, Any, Any, Optional[int]) -> None
CollectionStartEvent.__init__(self, anchor, tag, implicit, start_mark, end_mark, flow_style, comment, nr_items)
CollectionStartEvent.__init__(
self,
anchor,
tag,
implicit,
start_mark,
end_mark,
flow_style,
comment,
nr_items,
)
self.block_seq_indent = block_seq_indent


Expand Down
8 changes: 5 additions & 3 deletions lib/ruyaml/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,11 @@ def constructor(self):
# type: () -> Any
attr = '_' + sys._getframe().f_code.co_name
if not hasattr(self, attr):
cnst = self.Constructor(preserve_quotes=self.preserve_quotes,
preserve_bools=self.preserve_bools,
loader=self)
cnst = self.Constructor(
preserve_quotes=self.preserve_quotes,
preserve_bools=self.preserve_bools,
loader=self,
)
cnst.allow_duplicate_keys = self.allow_duplicate_keys
setattr(self, attr, cnst)
return getattr(self, attr)
Expand Down
2 changes: 1 addition & 1 deletion lib/ruyaml/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__(


class SequenceNode(CollectionNode):
__slots__ = ('block_seq_indent', )
__slots__ = ('block_seq_indent',)
id = 'sequence'

def __init__(
Expand Down
4 changes: 3 additions & 1 deletion lib/ruyaml/representer.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,9 @@ def set_block_seq_indent(self, node, sequence):
if not sequence.lc.data:
return
for lc_item in sequence.lc.data.values():
local_block_seq_indent = min(local_block_seq_indent, lc_item[1] - 2) # Why '2'?
local_block_seq_indent = min(
local_block_seq_indent, lc_item[1] - 2
) # Why '2'?
node.block_seq_indent = local_block_seq_indent

def merge_comments(self, node, comments):
Expand Down

0 comments on commit 7076482

Please sign in to comment.