From ffaab93d8964e7fbcbc2efe3399ae128fb4c5756 Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Sat, 6 Oct 2018 19:34:28 +0200 Subject: fix issue #245 regression on C parsing of explicit 1.1 source *When this change indeed resolves your problem, please **Close** this issue*. *(You can do so using the WorkFlow pull-down (close to the top right of this page))* --- CHANGES | 8 ++++++++ README.rst | 10 +++++++--- __init__.py | 4 ++-- _doc/_static/pypi.svg | 2 +- _test/roundtrip.py | 4 ++++ _test/test_issues.py | 1 - _test/test_z_data.py | 8 +++++--- main.py | 8 ++++---- resolver.py | 17 +++++++++++------ 9 files changed, 42 insertions(+), 20 deletions(-) diff --git a/CHANGES b/CHANGES index aaab1b7..cb6ee69 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,11 @@ +[0, 15, 72]: 2018-10-06 + - fix regression on explicit 1.1 loading with the C based scanner/parser + (reported by `Tomas Vavra `__) + +[0, 15, 72]: 2018-10-06 + - fix regression on explicit 1.1 loading with the C based scanner/parser + (reported by `Tomas Vavra `__) + [0, 15, 71]: 2018-09-26 - fix regression where handcrafted CommentedMaps could not be initiated (reported by `Dan Helfman `__) diff --git a/README.rst b/README.rst index 5422764..f466c7f 100644 --- a/README.rst +++ b/README.rst @@ -4,8 +4,8 @@ ruamel.yaml ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.15.71 -:updated: 2018-09-26 +:version: 0.15.72 +:updated: 2018-10-06 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/ :pypi: https://pypi.org/project/ruamel.yaml/ @@ -19,7 +19,7 @@ functionality will throw a warning before being changed/removed. but new functionality is likely only to be available via the new API. If your package uses ``ruamel.yaml`` and is not listed on PyPI, drop -me an email, preferably with some infomormation on how you use the +me an email, preferably with some information on how you use the package (or a link to bitbucket/github) and I'll keep you informed when the status of the API is stable enough to make the transition. @@ -54,6 +54,10 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.15.72 (2018-10-06): + - fix regression on explicit 1.1 loading with the C based scanner/parser + (reported by `Tomas Vavra `__) + 0.15.71 (2018-09-26): - some of the tests now live in YAML files in the `yaml.data `__ repository. diff --git a/__init__.py b/__init__.py index 9b815db..b9a3a44 100644 --- a/__init__.py +++ b/__init__.py @@ -7,8 +7,8 @@ if False: # MYPY _package_data = dict( full_package_name='ruamel.yaml', - version_info=(0, 15, 71), - __version__='0.15.71', + version_info=(0, 15, 72), + __version__='0.15.72', author='Anthon van der Neut', author_email='a.van.der.neut@ruamel.eu', description='ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order', # NOQA diff --git a/_doc/_static/pypi.svg b/_doc/_static/pypi.svg index b5019c7..19b9de5 100644 --- a/_doc/_static/pypi.svg +++ b/_doc/_static/pypi.svg @@ -1 +1 @@ - pypipypi0.15.710.15.71 + pypipypi0.15.720.15.72 diff --git a/_test/roundtrip.py b/_test/roundtrip.py index 8e1e66e..ee430a3 100644 --- a/_test/roundtrip.py +++ b/_test/roundtrip.py @@ -251,6 +251,10 @@ def save_and_run(program, base_dir=None, output=None, file_name=None, optimized= print('running:', *cmd) res = check_output(cmd, stderr=STDOUT, universal_newlines=True) if output is not None: + if '__pypy__' in sys.builtin_module_names: + res = res.splitlines(True) + res = [line for line in res if 'no version info' not in line] + res = ''.join(res) print('result: ', res, end='') print('expected:', output, end='') assert res == output diff --git a/_test/test_issues.py b/_test/test_issues.py index 4ccbff4..51cd5f7 100644 --- a/_test/test_issues.py +++ b/_test/test_issues.py @@ -514,7 +514,6 @@ class TestIssues: d0 = CommentedMap([('a', 'b')]) assert d0['a'] == 'b' - @pytest.mark.xfail(strict=True, reason='regression on Yes', raises=AssertionError) def test_issue_xxx(self): from ruamel.yaml import YAML inp = """ diff --git a/_test/test_z_data.py b/_test/test_z_data.py index 35c1ded..d106a2a 100644 --- a/_test/test_z_data.py +++ b/_test/test_z_data.py @@ -54,9 +54,11 @@ class YAMLData(object): return cls(constructor.construct_mapping(node)) return cls(node.value) + class Python(YAMLData): yaml_tag = '!Python' + class Output(YAMLData): yaml_tag = '!Output' @@ -144,7 +146,7 @@ class TestYAMLData(object): assert save_and_run(python.value, base_dir=tmpdir, output=data.value) == 0 - # this is executed by pytest the methods with names not starting with test_ + # this is executed by pytest the methods with names not starting with test_ # are helpers def test_yaml_data(self, yaml, tmpdir): from ruamel.yaml.compat import Mapping @@ -168,7 +170,7 @@ class TestYAMLData(object): elif isinstance(doc, Python): python = doc if typ is None: - typ = 'pyrun' + typ = 'python_run' elif isinstance(doc, YAMLData): data = doc else: @@ -187,7 +189,7 @@ class TestYAMLData(object): print('output:', output.value if output is not None else output) if typ == 'rt': self.round_trip(data, output, yaml_version=yaml_version) - elif typ == 'pyrun': + elif typ == 'python_run': self.run_python(python, output if output is not None else data, tmpdir) elif typ == 'load_assert': self.load_assert(data, confirm, yaml_version=yaml_version) diff --git a/main.py b/main.py index 2c5c7d5..140e696 100644 --- a/main.py +++ b/main.py @@ -394,17 +394,17 @@ class YAML(object): # if you just initialise the CParser, to much of resolver.py # is actually used rslvr = self.Resolver - if rslvr is ruamel.yaml.resolver.VersionedResolver: - rslvr = ruamel.yaml.resolver.Resolver + # if rslvr is ruamel.yaml.resolver.VersionedResolver: + # rslvr = ruamel.yaml.resolver.Resolver class XLoader(self.Parser, self.Constructor, rslvr): # type: ignore - def __init__(selfx, stream, version=None, preserve_quotes=None): + def __init__(selfx, stream, version=self.version, preserve_quotes=None): # type: (StreamTextType, Optional[VersionType], Optional[bool]) -> None # NOQA CParser.__init__(selfx, stream) selfx._parser = selfx._composer = selfx self.Constructor.__init__(selfx, loader=selfx) selfx.allow_duplicate_keys = self.allow_duplicate_keys - rslvr.__init__(selfx, loadumper=selfx) + rslvr.__init__(selfx, version=version, loadumper=selfx) self._stream = stream loader = XLoader(stream) diff --git a/resolver.py b/resolver.py index 2641a54..5da1fe3 100644 --- a/resolver.py +++ b/resolver.py @@ -316,8 +316,10 @@ class VersionedResolver(BaseResolver): and Yes/No/On/Off booleans. """ - def __init__(self, version=None, loader=None): - # type: (Optional[VersionType], Any) -> None + def __init__(self, version=None, loader=None, loadumper=None): + # type: (Optional[VersionType], Any, Any) -> None + if loader is None and loadumper is not None: + loader = loadumper BaseResolver.__init__(self, loader) self._loader_version = self.get_loader_version(version) self._version_implicit_resolver = {} # type: Dict[Any, Any] @@ -383,10 +385,13 @@ class VersionedResolver(BaseResolver): try: version = self.parser.yaml_version except AttributeError: - if hasattr(self.loadumper, 'typ'): - version = self.loadumper.version - else: - version = self.loadumper._serializer.use_version # dumping + try: + if hasattr(self.loadumper, 'typ'): + version = self.loadumper.version + else: + version = self.loadumper._serializer.use_version # dumping + except AttributeError: + version = None if version is None: version = self._loader_version if version is None: -- cgit v1.2.1