diff options
author | Anthon van der Neut <anthon@mnt.org> | 2018-08-14 21:00:50 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2018-08-14 21:00:50 +0200 |
commit | 3a1db0b45daaf5cf7d3587170f9571691cd82bf5 (patch) | |
tree | 8d9b9aa9a7af768e29b1398acaa4aca34fc36f8a | |
parent | ecd5f8dbaf580fa618205845374256a301d0675f (diff) | |
download | ruamel.yaml-3a1db0b45daaf5cf7d3587170f9571691cd82bf5.tar.gz |
fix issue #165 Python2 raising error when Unicode text involved in duplicate key warning.0.15.55
I could only reproduce this in Python2, finally fixed it.
*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))*
-rw-r--r-- | CHANGES | 16 | ||||
-rw-r--r-- | README.rst | 20 | ||||
-rw-r--r-- | __init__.py | 4 | ||||
-rw-r--r-- | _doc/_static/pypi.svg | 2 | ||||
-rw-r--r-- | _test/test_api_change.py | 1 | ||||
-rw-r--r-- | constructor.py | 13 |
6 files changed, 49 insertions, 7 deletions
@@ -1,3 +1,19 @@ +[0, 15, 55]: 2018-08-14 + + - unmade ``CommentedSeq`` a subclass of ``list``. It is now + indirectly a subclass of the standard + ``collections.abc.MutableSequence`` (without .abc if you are + still on Python2.7). If you do ``isinstance(yaml.load('[1, 2]'), + list)``) anywhere in your code replace ``list`` with + ``MutableSequence``. Directly, ``CommentedSeq`` is a subclass of + the abstract baseclass ``ruamel.yaml.compat.MutableScliceableSequence``, + with the result that *(extended) slicing is supported on + ``CommentedSeq``*. + (reported by `Stuart Berg <https://bitbucket.org/stuarteberg/>`__) + - duplicate keys (or their values) with non-ascii now correctly + report in Python2, instead of raising a Unicode error. + (Reported by `Jonathan Pyle <https://bitbucket.org/jonathan_pyle/>`__) + [0, 15, 54]: 2018-08-13 - fix issue where a comment could pop-up twice in the output (reported by @@ -4,8 +4,8 @@ ruamel.yaml ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.15.54 -:updated: 2018-08-13 +:version: 0.15.55 +:updated: 2018-08-14 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/ :pypi: https://pypi.org/project/ruamel.yaml/ @@ -54,6 +54,22 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.15.55 (2018-08-14): + + - unmade ``CommentedSeq`` a subclass of ``list``. It is now + indirectly a subclass of the standard + ``collections.abc.MutableSequence`` (without .abc if you are + still on Python2.7). If you do ``isinstance(yaml.load('[1, 2]'), + list)``) anywhere in your code replace ``list`` with + ``MutableSequence``. Directly, ``CommentedSeq`` is a subclass of + the abstract baseclass ``ruamel.yaml.compat.MutableScliceableSequence``, + with the result that *(extended) slicing is supported on + ``CommentedSeq``*. + (reported by `Stuart Berg <https://bitbucket.org/stuarteberg/>`__) + - duplicate keys (or their values) with non-ascii now correctly + report in Python2, instead of raising a Unicode error. + (Reported by `Jonathan Pyle <https://bitbucket.org/jonathan_pyle/>`__) + 0.15.54 (2018-08-13): - fix issue where a comment could pop-up twice in the output (reported by diff --git a/__init__.py b/__init__.py index cfddf1b..5c994e3 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, 54), - __version__='0.15.54', + version_info=(0, 15, 55), + __version__='0.15.55', 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 369335f..aa24ad4 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.15.54</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.15.54</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.15.55</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.15.55</text></g> </svg> diff --git a/_test/test_api_change.py b/_test/test_api_change.py index 43c8c90..b5b3d00 100644 --- a/_test/test_api_change.py +++ b/_test/test_api_change.py @@ -215,7 +215,6 @@ class TestFlowStyle: class TestOldAPI: @pytest.mark.skipif(sys.version_info >= (3, 0), reason='ok on Py3') - @pytest.mark.xfail(strict=True) def test_duplicate_keys_02(self): # Issue 165 unicode keys in error/warning from ruamel.yaml import safe_load diff --git a/constructor.py b/constructor.py index 9de28d0..8e1da70 100644 --- a/constructor.py +++ b/constructor.py @@ -248,11 +248,19 @@ class BaseConstructor(object): # type: (Any, Any, Any, Any, Any) -> None if key in mapping: if not self.allow_duplicate_keys: + mk = mapping.get(key) + if PY2: + if isinstance(key, unicode): + key = key.encode('utf-8') + if isinstance(value, unicode): + value = value.encode('utf-8') + if isinstance(mk, unicode): + mk = mk.encode('utf-8') args = [ 'while constructing a mapping', node.start_mark, 'found duplicate key "{}" with value "{}" ' - '(original value: "{}")'.format(key, value, mapping.get(key)), + '(original value: "{}")'.format(key, value, mk), key_node.start_mark, """ To suppress this check see: @@ -272,6 +280,9 @@ class BaseConstructor(object): # type: (Any, Any, Any, Any, Any) -> None if key in setting: if not self.allow_duplicate_keys: + if PY2: + if isinstance(key, unicode): + key = key.encode('utf-8') args = [ 'while constructing a set', node.start_mark, |