summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2019-01-08 09:03:34 +0100
committerAnthon van der Neut <anthon@mnt.org>2019-01-08 09:03:34 +0100
commitbdc07310846d253ddeac78f370db03df5d6e31b0 (patch)
tree960e48a41009998f6d1c32e6fb72930963672106
parent619842506decc4b036e06e5753f3f7476c036d41 (diff)
downloadruamel.yaml-bdc07310846d253ddeac78f370db03df5d6e31b0.tar.gz
resolves issue #274 replace dict with collections.OrderedDict when loading0.15.85
https://bitbucket.org/ruamel/yaml/issues/274/add-a-typ-ordered-for-a-middle-ground#comment-49783394 *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--CHANGES8
-rw-r--r--README.rst12
-rw-r--r--__init__.py4
-rw-r--r--_doc/_static/pypi.svg2
-rw-r--r--_test/test_api_change.py1
-rw-r--r--constructor.py10
6 files changed, 28 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index bb6f0ae..bb25af7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,11 @@
+[0, 15, 85]: 2019-01-08
+ - the types used by `SafeConstructor` for mappings and sequences can
+ now by set by assigning to `XXXConstructor.yaml_base_dict_type`
+ (and `..._list_type`), preventing the need to copy two methods
+ with 50+ lines that had `var = {}` hardcoded. (Implemented to
+ help solve an feature request by `Anthony Sottile
+ <https://bitbucket.org/asottile/>`__ in an easier way)
+
[0, 15, 84]: 2019-01-07
- fix for `CommentedMap.copy()` not returning `CommentedMap`, let alone copying comments etc.
(reported by `Anthony Sottile <https://bitbucket.org/asottile/>`__)
diff --git a/README.rst b/README.rst
index f42a5bd..7f929bb 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.84
-:updated: 2019-01-07
+:version: 0.15.85
+:updated: 2019-01-08
:documentation: http://yaml.readthedocs.io
:repository: https://bitbucket.org/ruamel/
:pypi: https://pypi.org/project/ruamel.yaml/
@@ -54,6 +54,14 @@ ChangeLog
.. should insert NEXT: at the beginning of line for next key (with empty line)
+0.15.85 (2019-01-08):
+ - the types used by `SafeConstructor` for mappings and sequences can
+ now by set by assigning to `XXXConstructor.yaml_base_dict_type`
+ (and `..._list_type`), preventing the need to copy two methods
+ with 50+ lines that had `var = {}` hardcoded. (Implemented to
+ help solve an feature request by `Anthony Sottile
+ <https://bitbucket.org/asottile/>`__ in an easier way)
+
0.15.84 (2019-01-07):
- fix for `CommentedMap.copy()` not returning `CommentedMap`, let alone copying comments etc.
(reported by `Anthony Sottile <https://bitbucket.org/asottile/>`__)
diff --git a/__init__.py b/__init__.py
index 5719064..8a0ef9e 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, 84),
- __version__='0.15.84',
+ version_info=(0, 15, 85),
+ __version__='0.15.85',
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 f62388f..4c05b38 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.84</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.15.84</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.85</text><text x="585" y="140" transform="scale(.1)" textLength="430">0.15.85</text></g> </svg>
diff --git a/_test/test_api_change.py b/_test/test_api_change.py
index 9bb26b5..3f3d411 100644
--- a/_test/test_api_change.py
+++ b/_test/test_api_change.py
@@ -146,6 +146,7 @@ class TestRead:
with pytest.raises(ConstructorError):
yaml.load(s)
# should parse fine
+ yaml = YAML(typ='safe')
for _ in yaml.parse(s):
pass
diff --git a/constructor.py b/constructor.py
index 65d6829..53e0d27 100644
--- a/constructor.py
+++ b/constructor.py
@@ -63,6 +63,8 @@ class BaseConstructor(object):
if self.loader is not None and getattr(self.loader, '_constructor', None) is None:
self.loader._constructor = self
self.loader = loader
+ self.yaml_base_dict_type = dict
+ self.yaml_base_list_type = list
self.constructed_objects = {} # type: Dict[Any, Any]
self.recursive_objects = {} # type: Dict[Any, Any]
self.state_generators = [] # type: List[Any]
@@ -207,13 +209,13 @@ class BaseConstructor(object):
raise ConstructorError(
None, None, 'expected a mapping node, but found %s' % node.id, node.start_mark
)
- total_mapping = {}
+ total_mapping = self.yaml_base_dict_type()
if getattr(node, 'merge', None) is not None:
todo = [(node.merge, False), (node.value, False)]
else:
todo = [(node.value, True)]
for values, check in todo:
- mapping = {} # type: Dict[Any, Any]
+ mapping = self.yaml_base_dict_type() # type: Dict[Any, Any]
for key_node, value_node in values:
# keys can be list -> deep
key = self.construct_object(key_node, deep=True)
@@ -686,13 +688,13 @@ class SafeConstructor(BaseConstructor):
def construct_yaml_seq(self, node):
# type: (Any) -> Any
- data = [] # type: List[Any]
+ data = self.yaml_base_list_type() # type: List[Any]
yield data
data.extend(self.construct_sequence(node))
def construct_yaml_map(self, node):
# type: (Any) -> Any
- data = {} # type: Dict[Any, Any]
+ data = self.yaml_base_dict_type() # type: Dict[Any, Any]
yield data
value = self.construct_mapping(node)
data.update(value)