diff --git a/_test/test_block_seq_local_indent.py b/_test/test_block_seq_local_indent.py index 9b19295..49eb940 100644 --- a/_test/test_block_seq_local_indent.py +++ b/_test/test_block_seq_local_indent.py @@ -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 class ScalarNodePositioned(ScalarNode): @@ -18,14 +19,13 @@ class ScalarNodePositioned(ScalarNode): 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) @@ -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): @@ -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( @@ -68,7 +70,6 @@ def round_trip_stabler( class TestStability: - def test_blockseq1(self): round_trip( """ @@ -101,8 +102,8 @@ def test_blockseq3(self): """ ) -class TestStabilityStabler: +class TestStabilityStabler: def test_blockseq1(self): round_trip_stabler( """ diff --git a/_test/test_bools.py b/_test/test_bools.py index d6620b3..3ed4085 100644 --- a/_test/test_bools.py +++ b/_test/test_bools.py @@ -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( @@ -31,7 +32,6 @@ def round_trip_stabler( class TestStability: - def test_lowercase_boolean(self): round_trip( """ diff --git a/lib/ruyaml/events.py b/lib/ruyaml/events.py index 7af91a1..e0a0fd9 100644 --- a/lib/ruyaml/events.py +++ b/lib/ruyaml/events.py @@ -186,7 +186,7 @@ def __init__( class SequenceStartEvent(CollectionStartEvent): - __slots__ = ('block_seq_indent', ) + __slots__ = ('block_seq_indent',) def __init__( self, @@ -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 diff --git a/lib/ruyaml/main.py b/lib/ruyaml/main.py index 19288c9..67a4fd1 100644 --- a/lib/ruyaml/main.py +++ b/lib/ruyaml/main.py @@ -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) diff --git a/lib/ruyaml/nodes.py b/lib/ruyaml/nodes.py index 311f329..63ef260 100644 --- a/lib/ruyaml/nodes.py +++ b/lib/ruyaml/nodes.py @@ -121,7 +121,7 @@ def __init__( class SequenceNode(CollectionNode): - __slots__ = ('block_seq_indent', ) + __slots__ = ('block_seq_indent',) id = 'sequence' def __init__( diff --git a/lib/ruyaml/representer.py b/lib/ruyaml/representer.py index 29812f5..8180ef7 100644 --- a/lib/ruyaml/representer.py +++ b/lib/ruyaml/representer.py @@ -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):