diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-06-03 14:34:51 +0100 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-06-03 15:12:36 +0100 |
commit | 49262bda8e5bc3a1886256a848618ae22229135e (patch) | |
tree | 293e9190acf877b600f4afc17aa85fcf5af0969c /tests | |
parent | 6b1f04769601328dfdd724103a4e08fc8623599c (diff) | |
download | buildstream-49262bda8e5bc3a1886256a848618ae22229135e.tar.gz |
_yaml.pyx: Forbid expected_type=Mapping, and remove isinstance check
Calls to `isinstance` can be particularily costly. Using type() is
much faster. The only known case where the `isinstance` was useful
is for dictionnaries where we would ask for a 'Mapping' instead.
Disallowing 'Mapping' for expected_type considerably speeds up the
calls to this functions.
Also add into NEWS
Diffstat (limited to 'tests')
-rw-r--r-- | tests/internals/yaml.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/tests/internals/yaml.py b/tests/internals/yaml.py index 6b26fdfaf..cd3bdc535 100644 --- a/tests/internals/yaml.py +++ b/tests/internals/yaml.py @@ -1,4 +1,3 @@ -from collections.abc import Mapping import os from io import StringIO @@ -108,12 +107,12 @@ def test_node_get(datafiles): assert isinstance(children, list) assert len(children) == 7 - child = _yaml.node_get(base, Mapping, 'children', indices=[6]) + child = _yaml.node_get(base, dict, 'children', indices=[6]) assert_provenance(filename, 20, 8, child, 'mood') - extra = _yaml.node_get(base, Mapping, 'extra') + extra = _yaml.node_get(base, dict, 'extra') with pytest.raises(LoadError) as exc: - _yaml.node_get(extra, Mapping, 'old') + _yaml.node_get(extra, dict, 'old') assert exc.value.reason == LoadErrorReason.INVALID_DATA @@ -189,8 +188,8 @@ def test_composite_preserve_originals(datafiles): base_copy = _yaml.node_copy(base) _yaml.composite_dict(base_copy, overlay) - copy_extra = _yaml.node_get(base_copy, Mapping, 'extra') - orig_extra = _yaml.node_get(base, Mapping, 'extra') + copy_extra = _yaml.node_get(base_copy, dict, 'extra') + orig_extra = _yaml.node_get(base, dict, 'extra') # Test that the node copy has the overridden value... assert _yaml.node_get(copy_extra, str, 'old') == 'override' @@ -474,7 +473,7 @@ def test_roundtrip_dump(datafiles, fromdisk): for v in node.values(): if isinstance(v, list): walk_list(v) - elif isinstance(v, Mapping): + elif isinstance(v, dict): walk_node(v) else: assert isinstance(v, str) @@ -483,7 +482,7 @@ def test_roundtrip_dump(datafiles, fromdisk): for v in l: if isinstance(v, list): walk_list(v) - elif isinstance(v, Mapping): + elif isinstance(v, dict): walk_node(v) else: assert isinstance(v, str) |