diff --git a/_test/test_bools.py b/_test/test_bools.py index 2ca629c..bd6add6 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 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( @@ -60,8 +62,8 @@ def round_trip_stabler( yaml = ruyaml.YAML() yaml.preserve_quotes = True yaml.preserve_bools = True - #yaml.Constructor = BetterRoundTripConstructor - #yaml.Representer = BetterRoundTripRepresenter + # yaml.Constructor = BetterRoundTripConstructor + # yaml.Representer = BetterRoundTripRepresenter data = yaml.load(doutp) buf = io.StringIO() yaml.dump(data, stream=buf) @@ -70,7 +72,6 @@ def round_trip_stabler( class TestStability: - def test_lowercase_boolean(self): round_trip( """ diff --git a/lib/ruyaml/main.py b/lib/ruyaml/main.py index fd0a4fb..7cf16a7 100644 --- a/lib/ruyaml/main.py +++ b/lib/ruyaml/main.py @@ -243,9 +243,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)