Skip to content

Commit d11c142

Browse files
committed
Import ABC from collections.abc instead of collections for Python 3.9 compatibility.
1 parent 529baba commit d11c142

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

odml/base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
"""
33
Collects common base functionality
44
"""
5-
import collections
65
import posixpath
76

87
from . import terminology
98
from .tools.doc_inherit import allow_inherit_docstring
109

10+
try:
11+
from collections.abc import Iterable
12+
except ImportError:
13+
from collections import Iterable
1114

1215
class BaseObject(object):
1316
_format = None
@@ -249,7 +252,7 @@ def append(self, section):
249252
if isinstance(section, BaseSection):
250253
self._sections.append(section)
251254
section._parent = self
252-
elif isinstance(section, collections.Iterable) and not isinstance(section, str):
255+
elif isinstance(section, Iterable) and not isinstance(section, str):
253256
raise ValueError("Use extend to add a list of Sections.")
254257
else:
255258
raise ValueError("Can only append objects of type Section.")
@@ -261,7 +264,7 @@ def extend(self, sec_list):
261264
:param sec_list: Iterable containing odML Section entries.
262265
"""
263266
from odml.section import BaseSection
264-
if not isinstance(sec_list, collections.Iterable):
267+
if not isinstance(sec_list, Iterable):
265268
raise TypeError("'%s' object is not iterable" % type(sec_list).__name__)
266269

267270
# Make sure only Sections with unique names will be added.

odml/section.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# -*- coding: utf-8
2-
import collections
32
import uuid
43

54
from . import base
@@ -11,6 +10,10 @@
1110
# it MUST however not be used to create any Property objects
1211
from .tools.doc_inherit import inherit_docstring, allow_inherit_docstring
1312

13+
try:
14+
from collections.abc import Iterable
15+
except ImportError:
16+
from collections import Iterable
1417

1518
@allow_inherit_docstring
1619
class BaseSection(base.Sectionable):
@@ -322,7 +325,7 @@ def append(self, obj):
322325
elif isinstance(obj, BaseProperty):
323326
self._props.append(obj)
324327
obj._parent = self
325-
elif isinstance(obj, collections.Iterable) and not isinstance(obj, str):
328+
elif isinstance(obj, Iterable) and not isinstance(obj, str):
326329
raise ValueError("odml.Section.append: "
327330
"Use extend to add a list of Sections or Properties.")
328331
else:
@@ -336,7 +339,7 @@ def extend(self, obj_list):
336339
337340
:param obj_list: Iterable containing Section and Property entries.
338341
"""
339-
if not isinstance(obj_list, collections.Iterable):
342+
if not isinstance(obj_list, Iterable):
340343
raise TypeError("'%s' object is not iterable" % type(obj_list).__name__)
341344

342345
# Make sure only Sections and Properties with unique names will be added.

0 commit comments

Comments
 (0)