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 8f2a770 commit f63bad8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
31 changes: 16 additions & 15 deletions _test/test_bools.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 @@ -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)
Expand All @@ -70,7 +72,6 @@ def round_trip_stabler(


class TestStability:

def test_lowercase_boolean(self):
round_trip(
"""
Expand Down
8 changes: 5 additions & 3 deletions lib/ruyaml/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f63bad8

Please sign in to comment.