From 208bdbb7b1d7488c197bce88578a128ac1cd743d Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Wed, 7 Apr 2021 21:13:57 +0200 Subject: fix for issue 382, error in format string --- CHANGES | 6 ++++++ README.rst | 10 ++++++++-- __init__.py | 4 ++-- _doc/_static/pypi.svg | 2 +- _test/test_z_olddata.py | 3 ++- composer.py | 5 ++++- error.py | 13 +++++++++++++ main.py | 3 ++- parser.py | 3 ++- 9 files changed, 40 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 8705613..46a0aea 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +[0, 17, 3]: 2021-04-07 + - fix for issue 382 caused by an error in a format string (reported by + `William Kimball `__) + - allow expansion of aliases by setting ``yaml.composer.return_alias = lambda s: copy.deepcopy(s)`` + (as per `Stackoverflow answer `__) + [0, 17, 2]: 2021-03-29 - change -py2.py3-none-any.whl to -py3-none-any.whl, and remove 0.17.1 diff --git a/README.rst b/README.rst index a1d8720..7063d9b 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.17.2 -:updated: 2021-03-29 +:version: 0.17.3 +:updated: 2021-04-07 :documentation: http://yaml.readthedocs.io :repository: https://sourceforge.net/projects/ruamel-yaml/ :pypi: https://pypi.org/project/ruamel.yaml/ @@ -65,6 +65,12 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.17.3 (2021-04-07): + - fix for issue 382 caused by an error in a format string (reported by + `William Kimball `__) + - allow expansion of aliases by setting ``yaml.composer.return_alias = lambda s: copy.deepcopy(s)`` + (as per `Stackoverflow answer `__) + 0.17.2 (2021-03-29): - change -py2.py3-none-any.whl to -py3-none-any.whl, and remove 0.17.1 diff --git a/__init__.py b/__init__.py index ecffcc4..1c22d65 100644 --- a/__init__.py +++ b/__init__.py @@ -5,8 +5,8 @@ if False: # MYPY _package_data = dict( full_package_name='ruamel.yaml', - version_info=(0, 17, 2), - __version__='0.17.2', + version_info=(0, 17, 3), + __version__='0.17.3', 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 f365455..07a1442 100644 --- a/_doc/_static/pypi.svg +++ b/_doc/_static/pypi.svg @@ -1 +1 @@ - pypipypi0.17.20.17.2 + pypipypi0.17.30.17.3 diff --git a/_test/test_z_olddata.py b/_test/test_z_olddata.py index 3857652..89b7053 100644 --- a/_test/test_z_olddata.py +++ b/_test/test_z_olddata.py @@ -15,13 +15,13 @@ args = [] def test_data(): import test_appliance # NOQA + warnings.simplefilter('ignore', PendingDeprecationWarning) collections = [] import test_yaml collections.append(test_yaml) test_appliance.run(collections, args) - # @pytest.mark.skipif(not ruamel.yaml.__with_libyaml__, # reason="no libyaml") @@ -32,6 +32,7 @@ def test_data_ext(): import test_appliance # NOQA warnings.simplefilter('ignore', ruamel.yaml.error.UnsafeLoaderWarning) + warnings.simplefilter('ignore', PendingDeprecationWarning) if ruamel.yaml.__with_libyaml__: import test_yaml_ext diff --git a/composer.py b/composer.py index 3c8ba1c..c47c85d 100644 --- a/composer.py +++ b/composer.py @@ -104,6 +104,9 @@ class Composer(object): self.anchors = {} return node + def return_alias(self, a): + return a + def compose_node(self, parent, index): # type: (Any, Any) -> Any if self.parser.check_event(AliasEvent): @@ -116,7 +119,7 @@ class Composer(object): _F('found undefined alias {alias!r}', alias=alias), event.start_mark, ) - return self.anchors[alias] + return self.return_alias(self.anchors[alias]) event = self.parser.peek_event() anchor = event.anchor if anchor is not None: # have an anchor diff --git a/error.py b/error.py index 6853e2d..04c4c24 100644 --- a/error.py +++ b/error.py @@ -114,6 +114,19 @@ class StringMark(StreamMark): where += ':\n' + snippet return where + def __repr__(self): + # type: () -> Any + snippet = self.get_snippet() + where = _F( + ' in "{sname!s}", line {sline1:d}, column {scolumn1:d}', + sname=self.name, + sline1=self.line + 1, + scolumn1=self.column + 1, + ) + if snippet is not None: + where += ':\n' + snippet + return where + class CommentMark(object): __slots__ = ('column',) diff --git a/main.py b/main.py index 660e4a7..efde0e1 100644 --- a/main.py +++ b/main.py @@ -150,6 +150,7 @@ class YAML(object): self.scalar_after_indicator = None # [a, b: 1, c: {d: 2}] vs. [a, {b: 1}, {c: {d: 2}}] self.brace_single_entry_mapping_in_flow_sequence = False + self.comment_handling = None for module in self.plug_ins: if getattr(module, 'typ', None) in self.typ: typ_found += 1 @@ -1614,7 +1615,7 @@ class YAMLObjectMetaclass(type): def __init__(cls, name, bases, kwds): # type: (Any, Any, Any) -> None - super(YAMLObjectMetaclass, cls).__init__(name, bases, kwds) + super().__init__(name, bases, kwds) if 'yaml_tag' in kwds and kwds['yaml_tag'] is not None: cls.yaml_constructor.add_constructor(cls.yaml_tag, cls.from_yaml) # type: ignore cls.yaml_representer.add_representer(cls, cls.to_yaml) # type: ignore diff --git a/parser.py b/parser.py index f1ee9de..76c089b 100644 --- a/parser.py +++ b/parser.py @@ -357,6 +357,7 @@ class Parser(object): start_mark = end_mark = tag_mark = None if self.scanner.check_token(AnchorToken): token = self.scanner.get_token() + token.move_comment(self.scanner.peek_token()) start_mark = token.start_mark end_mark = token.end_mark anchor = token.value @@ -730,7 +731,7 @@ class Parser(object): raise ParserError( 'while parsing a flow mapping', self.marks[-1], - _F("expected ',' or '}', but got {token_id!r}", token_id=token.id), + _F("expected ',' or '}}', but got {token_id!r}", token_id=token.id), token.start_mark, ) if self.scanner.check_token(KeyToken): -- cgit v1.2.1