summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2021-04-07 21:13:57 +0200
committerAnthon van der Neut <anthon@mnt.org>2021-04-07 21:13:57 +0200
commit208bdbb7b1d7488c197bce88578a128ac1cd743d (patch)
tree881c73ab9e563a3537dfeb7deec7105cea26c39b
parent8993ebf6eece99d1bae8690d9fb2bb816196d4a6 (diff)
downloadruamel.yaml-0.17.3.tar.gz
fix for issue 382, error in format string0.17.3
-rw-r--r--CHANGES6
-rw-r--r--README.rst10
-rw-r--r--__init__.py4
-rw-r--r--_doc/_static/pypi.svg2
-rw-r--r--_test/test_z_olddata.py3
-rw-r--r--composer.py5
-rw-r--r--error.py13
-rw-r--r--main.py3
-rw-r--r--parser.py3
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 <https://sourceforge.net/u/william303/>`__)
+ - allow expansion of aliases by setting ``yaml.composer.return_alias = lambda s: copy.deepcopy(s)``
+ (as per `Stackoverflow answer <https://stackoverflow.com/a/66983530/1307905>`__)
+
[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 <https://sourceforge.net/u/william303/>`__)
+ - allow expansion of aliases by setting ``yaml.composer.return_alias = lambda s: copy.deepcopy(s)``
+ (as per `Stackoverflow answer <https://stackoverflow.com/a/66983530/1307905>`__)
+
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 @@
-<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="86" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="86" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h33v20H0z"/><path fill="#007ec6" d="M33 0h53v20H33z"/><path fill="url(#b)" d="M0 0h86v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="175" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="230">pypi</text><text x="175" y="140" transform="scale(.1)" textLength="230">pypi</text><text x="585" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">0.17.2</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.17.2</text></g> </svg>
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="86" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="86" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h33v20H0z"/><path fill="#007ec6" d="M33 0h53v20H33z"/><path fill="url(#b)" d="M0 0h86v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="175" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="230">pypi</text><text x="175" y="140" transform="scale(.1)" textLength="230">pypi</text><text x="585" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">0.17.3</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.17.3</text></g> </svg>
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):