Skip to content

Commit 040a2f4

Browse files
committed
Corrects import of MutableMapping class for python 3.3+
MutableMapping class is now imported from collections.abc instead of collections. This change was made to python standard library in version 3.3. collections.MutableMapping has been provided for backwards compatability up to python 3.7 but will no longer be available from python 3.8. A try/catch statement is used with the import to retain backwords compatibility with python version < 3.3 including python 2.
1 parent c639d9a commit 040a2f4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

nibabel/streamlines/tractogram.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import copy
22
import numbers
33
import numpy as np
4-
import collections
54
from warnings import warn
65

6+
try:
7+
from collections.abc import MutableMapping
8+
except ImportError:
9+
# PY2 compatibility
10+
from collections import MutableMapping
11+
712
from nibabel.affines import apply_affine
813

914
from .array_sequence import ArraySequence
@@ -19,7 +24,7 @@ def is_lazy_dict(obj):
1924
return is_data_dict(obj) and callable(list(obj.store.values())[0])
2025

2126

22-
class SliceableDataDict(collections.MutableMapping):
27+
class SliceableDataDict(MutableMapping):
2328
""" Dictionary for which key access can do slicing on the values.
2429
2530
This container behaves like a standard dictionary but extends key access to
@@ -181,7 +186,7 @@ def _extend_entry(self, key, value):
181186
self[key].extend(value)
182187

183188

184-
class LazyDict(collections.MutableMapping):
189+
class LazyDict(MutableMapping):
185190
""" Dictionary of generator functions.
186191
187192
This container behaves like a dictionary but it makes sure its elements are

0 commit comments

Comments
 (0)