summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2021-08-28 20:59:55 +0200
committerAnthon van der Neut <anthon@mnt.org>2021-08-28 20:59:55 +0200
commita67ac7764d4d599d4b78addcf4126fc837292705 (patch)
tree76650f45427e5f54544f27e03c92c0cbc439209d
parente9758fbad489545478ecb9901c27d0627ca504fc (diff)
downloadruamel.yaml-a67ac7764d4d599d4b78addcf4126fc837292705.tar.gz
handle 397 with newline0.17.16
-rw-r--r--CHANGES3
-rw-r--r--README.rst5
-rw-r--r--__init__.py4
-rw-r--r--_doc/_static/pypi.svg2
-rw-r--r--comments.py11
5 files changed, 16 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index 336bbfd..06e6680 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+[0, 17, 16]: 2021-08-28
+ - also handle issue 397 when comment is newline
+
[0, 17, 15]: 2021-08-28
- fix issue 397, insert comment before key when a comment between key and value exists
(reported by `Bastien gerard <https://sourceforge.net/u/bagerard/>`__)
diff --git a/README.rst b/README.rst
index 73ac449..a9cd69e 100644
--- a/README.rst
+++ b/README.rst
@@ -4,7 +4,7 @@ ruamel.yaml
``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python.
-:version: 0.17.15
+:version: 0.17.16
:updated: 2021-08-28
:documentation: http://yaml.readthedocs.io
:repository: https://sourceforge.net/projects/ruamel-yaml/
@@ -72,6 +72,9 @@ ChangeLog
.. should insert NEXT: at the beginning of line for next key (with empty line)
+0.17.16 (2021-08-28):
+ - also handle issue 397 when comment is newline
+
0.17.15 (2021-08-28):
- fix issue 397, insert comment before key when a comment between key and value exists
(reported by `Bastien gerard <https://sourceforge.net/u/bagerard/>`__)
diff --git a/__init__.py b/__init__.py
index 941b925..53e8b51 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, 15),
- __version__='0.17.15',
+ version_info=(0, 17, 16),
+ __version__='0.17.16',
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 6300936..c59acf1 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.15</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.17.15</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.16</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.17.16</text></g> </svg>
diff --git a/comments.py b/comments.py
index 6d2eb6b..053b4f1 100644
--- a/comments.py
+++ b/comments.py
@@ -391,13 +391,14 @@ class CommentedBase:
after = after[:-1] # strip final newline if there
start_mark = CommentMark(indent)
c = self.ca.items.setdefault(key, [None, [], None, None])
- if before == '\n':
- c[1].append(comment_token("", start_mark))
- elif before:
+ if before is not None:
if c[1] is None:
c[1] = []
- for com in before.split('\n'):
- c[1].append(comment_token(com, start_mark))
+ if before == '\n':
+ c[1].append(comment_token("", start_mark))
+ else:
+ for com in before.split('\n'):
+ c[1].append(comment_token(com, start_mark))
if after:
start_mark = CommentMark(after_indent)
if c[3] is None: