From 029e34d4f9054a53fb2cf914cec2fff7b217d761 Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Sun, 3 Dec 2017 11:06:38 +0100 Subject: allow None stream if transforming If YAML.dump() is passed a transform function, specifying None will ignore the return value of that function. --- CHANGES | 7 +++++++ README.rst | 11 +++++++++-- __init__.py | 4 ++-- main.py | 5 ++++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 5b61f46..7cc5fd3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,10 @@ +[0, 15, 35]: 2017-12-03 + - allow ``None`` as stream when specifying ``transform`` parameters to + ``YAML.dump()``. + This is useful if the transforming function doesn't return a meaningful value + (inspired by `StackOverflow `__ by + `rsaw `__). + [0, 15, 34]: 2017-09-17 - fix for issue 157: CDumper not dumping floats (reported by Jan Smitka) diff --git a/README.rst b/README.rst index f47e088..7da68db 100644 --- a/README.rst +++ b/README.rst @@ -33,7 +33,14 @@ when the status of the API is stable enough to make the transition. ChangeLog ========= -.. should insert NEXT: at the beginning of line for next key +.. should insert NEXT: at the beginning of line for next key (with empty line) + +0.15.35 (2017-12-03): + - allow ``None`` as stream when specifying ``transform`` parameters to + ``YAML.dump()``. + This is useful if the transforming function doesn't return a meaningful value + (inspired by `StackOverflow `__ by + `rsaw `__). 0.15.34 (2017-09-17): - fix for issue 157: CDumper not dumping floats (reported by Jan Smitka) @@ -99,7 +106,7 @@ ChangeLog - fix for round_tripping singe excl. mark tags doubling (reported and fix by Jan Brezina) 0.15.21 (2017-07-25): - - fix for writing unicode in new API, (reported on + - fix for writing unicode in new API, (reported on `StackOverflow `__ 0.15.20 (2017-07-23): diff --git a/__init__.py b/__init__.py index 9da7f51..7b190f3 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, 34), - __version__='0.15.34', + version_info=(0, 15, 35), + __version__='0.15.35', 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/main.py b/main.py index 1b5c2d0..e933210 100644 --- a/main.py +++ b/main.py @@ -399,7 +399,10 @@ class YAML(object): val = stream.getvalue() # type: ignore if self.encoding: val = val.decode(self.encoding) - fstream.write(transform(val)) + if fstream is None: + transform(val) + else: + fstream.write(transform(val)) return None def get_serializer_representer_emitter(self, stream, tlca): -- cgit v1.2.1