From 51d26b878717cf00bee0b961f39e0f14a7e9cdab Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Tue, 22 Jan 2019 22:24:56 +0100 Subject: fix indexing error on empty list for merge-key position --- CHANGES | 8 ++++++++ README.rst | 8 ++++++-- __init__.py | 4 ++-- _doc/_static/pypi.svg | 2 +- main.py | 2 +- representer.py | 5 ++++- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index d56f30e..574758a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,11 @@ +[0, 15, 87]: 2019-01-22 + - fix problem with empty lists and the code to reinsert merge keys (reported via email + by Zaloo) + +[0, 15, 87]: 2019-01-22 + - fix problem with empty lists and the code to reinsert merge keys (reported via email + by Zaloo) + [0, 15, 86]: 2019-01-16 - reinsert merge key in its old position (reported by grumbler on `__) diff --git a/README.rst b/README.rst index 809dd10..b62889d 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.86 -:updated: 2019-01-16 +:version: 0.15.87 +:updated: 2019-01-22 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/ :pypi: https://pypi.org/project/ruamel.yaml/ @@ -54,6 +54,10 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.15.87 (2019-01-22): + - fix problem with empty lists and the code to reinsert merge keys (reported via email + by Zaloo) + 0.15.86 (2019-01-16): - reinsert merge key in its old position (reported by grumbler on `__) diff --git a/__init__.py b/__init__.py index 1cb3f30..f03f94d 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, 86), - __version__='0.15.86', + version_info=(0, 15, 87), + __version__='0.15.87', 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 23fc356..a142d11 100644 --- a/_doc/_static/pypi.svg +++ b/_doc/_static/pypi.svg @@ -1 +1 @@ - pypipypi0.15.860.15.86 + pypipypi0.15.870.15.87 diff --git a/main.py b/main.py index f06c52e..184c7ad 100644 --- a/main.py +++ b/main.py @@ -324,7 +324,7 @@ class YAML(object): """ if not hasattr(stream, 'read') and hasattr(stream, 'open'): # pathlib.Path() instance - with stream.open('r') as fp: # type: ignore + with stream.open('rb') as fp: # type: ignore return self.load(fp) constructor, parser = self.get_constructor_parser(stream) try: diff --git a/representer.py b/representer.py index 7b2f007..859887c 100644 --- a/representer.py +++ b/representer.py @@ -1002,7 +1002,10 @@ class RoundTripRepresenter(SafeRepresenter): except AttributeError: item_comments = {} merge_list = [m[1] for m in getattr(mapping, merge_attrib, [])] - merge_pos = getattr(mapping, merge_attrib, [[0]])[0][0] + try: + merge_pos = getattr(mapping, merge_attrib, [[0]])[0][0] + except IndexError: + merge_pos = 0 item_count = 0 if bool(merge_list): items = mapping.non_merged_items() -- cgit v1.2.1