Skip to contentSkip to conversation

lib/oe: Fix collections ABCs DeprecationWarning in Python 3.7+

PATCH New Khem Raj 1 participant 1 message Aug 8, 2018

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/1 lib/oe: Fix collections ABCs DeprecationWarning in Python 3.7+

- Prefer collections.abc (new in Python 3.3) over collections for abstract base classes

- In Python 3.8, the abstract base classes in collections.abc will no longer be exposed in the regular collections module. This will help create a clearer distinction between the concrete classes and the abstract base classes."

- https://docs.python.org/3.7/whatsnew/3.7.html#deprecated

- see https://github.com/python/cpython/commit/c66f9f8d3909f588c251957d499599a1680e2320

---
 meta/lib/oe/maketype.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
meta/lib/oe/maketype.py +7 -2
index f88981dd90..c36e7b5604 100644
@@ -7,7 +7,12 @@ the arguments of the type's factory for details.
 
 import inspect
 import oe.types as types
-import collections
+try:
+    # Python 3.7+
+    from collections.abc import Callable
+except ImportError:
+    # Python < 3.7
+    from collections import Callable
 
 available_types = {}
 
@@ -96,7 +101,7 @@ for name in dir(types):
         continue
 
     obj = getattr(types, name)
-    if not isinstance(obj, collections.Callable):
+    if not isinstance(obj, Callable):
         continue
 
     register(name, obj)
Signature · 1 line
2.18.0