From bce1095295d4a058ed665efde34b22c83b77c8fe Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Wed, 26 Sep 2018 23:05:03 +0200 Subject: fix issue #238 construct recursive objects *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 | 17 +++++++++++++++-- __init__.py | 4 ++-- _doc/_static/pypi.svg | 2 +- _test/test_issues.py | 2 ++ _test/test_z_olddata.py | 41 +++++++++++++++++++++++++++++++++++++++++ constructor.py | 12 +++++++----- 7 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 _test/test_z_olddata.py diff --git a/CHANGES b/CHANGES index 2b64da8..aaab1b7 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,11 @@ +[0, 15, 71]: 2018-09-26 + - fix regression where handcrafted CommentedMaps could not be initiated (reported by + `Dan Helfman `__) + - fix regression with non-root literal scalars that needed indent indicator + (reported by `Clark Breyman `__) + - tag:yaml.org,2002:python/object/apply now also uses __qualname__ on PY3 + (reported by `Douglas RAILLARD `__) + [0, 15, 70]: 2018-09-21 - reverted CommentedMap and CommentedSeq to subclass ordereddict resp. list, reimplemented merge maps so that both ``dict(**commented_map_instance)`` and JSON diff --git a/README.rst b/README.rst index 04f6783..5422764 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.70 -:updated: 2018-09-21 +:version: 0.15.71 +:updated: 2018-09-26 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/ :pypi: https://pypi.org/project/ruamel.yaml/ @@ -54,6 +54,19 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.15.71 (2018-09-26): + - some of the tests now live in YAML files in the + `yaml.data `__ repository. + ``_test/test_z_data.py`` processes these. + - fix regression where handcrafted CommentedMaps could not be initiated (reported by + `Dan Helfman `__) + - fix regression with non-root literal scalars that needed indent indicator + (reported by `Clark Breyman `__) + - tag:yaml.org,2002:python/object/apply now also uses __qualname__ on PY3 + (reported by `Douglas RAILLARD `__) + - issue with self-referring object creation + (reported and fix by `Douglas RAILLARD `__) + 0.15.70 (2018-09-21): - reverted CommentedMap and CommentedSeq to subclass ordereddict resp. list, reimplemented merge maps so that both ``dict(**commented_map_instance)`` and JSON diff --git a/__init__.py b/__init__.py index 6ffb2d4..9b815db 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, 70), - __version__='0.15.70', + version_info=(0, 15, 71), + __version__='0.15.71', 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 8b244c0..b5019c7 100644 --- a/_doc/_static/pypi.svg +++ b/_doc/_static/pypi.svg @@ -1 +1 @@ - pypipypi0.15.700.15.70 + pypipypi0.15.710.15.71 diff --git a/_test/test_issues.py b/_test/test_issues.py index 5ee5125..fcf1094 100644 --- a/_test/test_issues.py +++ b/_test/test_issues.py @@ -510,9 +510,11 @@ class TestIssues: def test_issue_242(self): from ruamel.yaml.comments import CommentedMap + d0 = CommentedMap([('a', 'b')]) assert d0['a'] == 'b' + # @pytest.mark.xfail(strict=True, reason='bla bla', raises=AssertionError) # def test_issue_xxx(self): # inp = """ diff --git a/_test/test_z_olddata.py b/_test/test_z_olddata.py new file mode 100644 index 0000000..91d89db --- /dev/null +++ b/_test/test_z_olddata.py @@ -0,0 +1,41 @@ +# coding: utf-8 + +from __future__ import print_function + +import sys +import os +import pytest # NOQA + +sys.path.insert(0, os.path.dirname(__file__) + '/lib') + +import warnings # NOQA + + +args = [] + + +def test_data(): + import test_appliance # NOQA + + collections = [] + import test_yaml + + collections.append(test_yaml) + test_appliance.run(collections, args) + + +# @pytest.mark.skipif(not ruamel.yaml.__with_libyaml__, +# reason="no libyaml") + + +def test_data_ext(): + collections = [] + import ruamel.yaml # NOQA + import test_appliance # NOQA + + warnings.simplefilter('ignore', ruamel.yaml.error.UnsafeLoaderWarning) + if ruamel.yaml.__with_libyaml__: + import test_yaml_ext + + collections.append(test_yaml_ext) + test_appliance.run(collections, args) diff --git a/constructor.py b/constructor.py index 6448067..245e9f7 100644 --- a/constructor.py +++ b/constructor.py @@ -133,9 +133,10 @@ class BaseConstructor(object): old_deep = self.deep_construct self.deep_construct = True if node in self.recursive_objects: - raise ConstructorError( - None, None, 'found unconstructable recursive node', node.start_mark - ) + return self.recursive_objects[node] + # raise ConstructorError( + # None, None, 'found unconstructable recursive node', node.start_mark + # ) self.recursive_objects[node] = None constructor = None # type: Any tag_suffix = None @@ -914,9 +915,10 @@ class Constructor(SafeConstructor): # Format: # !!python/object:module.name { ... state ... } instance = self.make_python_instance(suffix, node, newobj=True) + self.recursive_objects[node] = instance yield instance - # deep = hasattr(instance, '__setstate__') - state = self.construct_mapping(node, deep=False) + deep = hasattr(instance, '__setstate__') + state = self.construct_mapping(node, deep=deep) self.set_python_instance_state(instance, state) def construct_python_object_apply(self, suffix, node, newobj=False): -- cgit v1.2.1