Skip to content

Commit 9959328

Browse files
The-Compileringydotnet
authored andcommitted
Import Hashable from collections.abc
In Python 3.7, importing ABCs directly from the 'collections' module shows a warning (and in Python 3.8 it will stop working) - see python/cpython@c66f9f8 Since this is only done in lib3/ which is Python 3 only, we can unconditionally import it from collections.abc instead. This fixes the following DeprecationWarning: .../site-packages/yaml/__init__.py:75: in load return loader.get_single_data() .../site-packages/yaml/constructor.py:37: in get_single_data return self.construct_document(node) .../site-packages/yaml/constructor.py:46: in construct_document for dummy in generator: .../site-packages/yaml/constructor.py:398: in construct_yaml_map value = self.construct_mapping(node) .../site-packages/yaml/constructor.py:204: in construct_mapping return super().construct_mapping(node, deep=deep) .../site-packages/yaml/constructor.py:126: in construct_mapping if not isinstance(key, collections.Hashable): _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ name = 'Hashable' def __getattr__(name): # For backwards compatibility, continue to make the collections ABCs # through Python 3.6 available through the collections module. # Note, no new collections ABCs were added in Python 3.7 if name in _collections_abc.__all__: obj = getattr(_collections_abc, name) import warnings warnings.warn("Using or importing the ABCs from 'collections' instead " "of from 'collections.abc' is deprecated, " "and in 3.8 it will stop working", > DeprecationWarning, stacklevel=2) E DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
1 parent ccc40f3 commit 9959328

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib3/yaml/constructor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .error import *
66
from .nodes import *
77

8-
import collections, datetime, base64, binascii, re, sys, types
8+
import collections.abc, datetime, base64, binascii, re, sys, types
99

1010
class ConstructorError(MarkedYAMLError):
1111
pass
@@ -123,7 +123,7 @@ def construct_mapping(self, node, deep=False):
123123
mapping = {}
124124
for key_node, value_node in node.value:
125125
key = self.construct_object(key_node, deep=deep)
126-
if not isinstance(key, collections.Hashable):
126+
if not isinstance(key, collections.abc.Hashable):
127127
raise ConstructorError("while constructing a mapping", node.start_mark,
128128
"found unhashable key", key_node.start_mark)
129129
value = self.construct_object(value_node, deep=deep)

0 commit comments

Comments
 (0)