Skip to content

Commit

Permalink
enhancement: allow YAML parser loading primitive types' data
Browse files Browse the repository at this point in the history
allow YAML parser loading primitive types' data other than dict data
such like lists, numbers and strings, and add a test case to check it.
  • Loading branch information
ssato committed Jun 17, 2018
1 parent 6efec3e commit 71f7b94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 5 additions & 1 deletion anyconfig/backend/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ def _yml_load(stream, container, **options):
options["Loader"] = _customized_loader(container)

ret = _yml_fnc("load", stream, **_filter_from_options("ac_dict", options))
return anyconfig.backend.base.safe_container(ret, container, **options)
if ret is None:
return container()

return ret


def _yml_dump(cnf, stream, **options):
Expand Down Expand Up @@ -216,6 +219,7 @@ class Parser(anyconfig.backend.base.StreamParser):
"allow_unicode", "line_break", "encoding", "explicit_start",
"explicit_end", "version", "tags"]
_ordered = True
_allow_primitives = True
_dict_opts = ["ac_dict"]

load_from_stream = anyconfig.backend.base.to_method(_yml_load)
Expand Down
4 changes: 1 addition & 3 deletions tests/backend/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import os
import anyconfig.backend.yaml as TT
import anyconfig.globals
import tests.backend.common as TBC

from anyconfig.compat import OrderedDict
Expand Down Expand Up @@ -62,7 +61,6 @@ def test_18_load__list(self):

cnf = self.psr.load(ioi)
self.assertTrue(cnf)
key = anyconfig.globals.PRIMITIVES_TO_DICT_KEY
self._assert_dicts_equal(cnf, ref=OrderedDict({key: [1, 2]}))
self.assertEqual(cnf, [1, 2])

# vim:sw=4:ts=4:et:

0 comments on commit 71f7b94

Please sign in to comment.