Skip to content

MAINT: Import abstract classes from collections.abc for Python 3.8 compatibility #711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions nibabel/cifti2/cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
'''
from __future__ import division, print_function, absolute_import
import re
import collections

try:
from collections.abc import MutableSequence, MutableMapping, Iterable
except ImportError:
# PY2 compatibility
from collections import MutableSequence, MutableMapping, Iterable
from collections import OrderedDict
from .. import xmlutils as xml
from ..filebasedimages import FileBasedHeader
from ..dataobj_images import DataobjImage
Expand Down Expand Up @@ -104,7 +108,7 @@ def _underscore(string):
return re.sub(r'([a-z0-9])([A-Z])', r'\1_\2', string).lower()


class Cifti2MetaData(xml.XmlSerializable, collections.MutableMapping):
class Cifti2MetaData(xml.XmlSerializable, MutableMapping):
""" A list of name-value pairs

* Description - Provides a simple method for user-supplied metadata that
Expand All @@ -124,7 +128,7 @@ class Cifti2MetaData(xml.XmlSerializable, collections.MutableMapping):
data : list of (name, value) tuples
"""
def __init__(self, metadata=None):
self.data = collections.OrderedDict()
self.data = OrderedDict()
if metadata is not None:
self.update(metadata)

Expand Down Expand Up @@ -173,7 +177,7 @@ def _to_xml_element(self):
return metadata


class Cifti2LabelTable(xml.XmlSerializable, collections.MutableMapping):
class Cifti2LabelTable(xml.XmlSerializable, MutableMapping):
""" CIFTI2 label table: a sequence of ``Cifti2Label``s

* Description - Used by NamedMap when IndicesMapToDataType is
Expand All @@ -191,7 +195,7 @@ class Cifti2LabelTable(xml.XmlSerializable, collections.MutableMapping):
"""

def __init__(self):
self._labels = collections.OrderedDict()
self._labels = OrderedDict()

def __len__(self):
return len(self._labels)
Expand Down Expand Up @@ -427,7 +431,7 @@ def _to_xml_element(self):
return surf


class Cifti2VoxelIndicesIJK(xml.XmlSerializable, collections.MutableSequence):
class Cifti2VoxelIndicesIJK(xml.XmlSerializable, MutableSequence):
"""CIFTI2 VoxelIndicesIJK: Set of voxel indices contained in a structure

* Description - Identifies the voxels that model a brain structure, or
Expand Down Expand Up @@ -509,7 +513,7 @@ def _to_xml_element(self):
return vox_ind


class Cifti2Vertices(xml.XmlSerializable, collections.MutableSequence):
class Cifti2Vertices(xml.XmlSerializable, MutableSequence):
"""CIFTI2 vertices - association of brain structure and a list of vertices

* Description - Contains a BrainStructure type and a list of vertex indices
Expand Down Expand Up @@ -733,7 +737,7 @@ def _to_xml_element(self):
return volume


class Cifti2VertexIndices(xml.XmlSerializable, collections.MutableSequence):
class Cifti2VertexIndices(xml.XmlSerializable, MutableSequence):
"""CIFTI2 vertex indices: vertex indices for an associated brain model

The vertex indices (which are independent for each surface, and
Expand Down Expand Up @@ -889,7 +893,7 @@ def _to_xml_element(self):
return brain_model


class Cifti2MatrixIndicesMap(xml.XmlSerializable, collections.MutableSequence):
class Cifti2MatrixIndicesMap(xml.XmlSerializable, MutableSequence):
"""Class for Matrix Indices Map

* Description - Provides a mapping between matrix indices and their
Expand Down Expand Up @@ -1076,7 +1080,7 @@ def _to_xml_element(self):
return mat_ind_map


class Cifti2Matrix(xml.XmlSerializable, collections.MutableSequence):
class Cifti2Matrix(xml.XmlSerializable, MutableSequence):
""" CIFTI2 Matrix object

This is a list-like container where the elements are instances of
Expand Down Expand Up @@ -1122,7 +1126,7 @@ def _get_indices_from_mim(self, mim):
applies_to_matrix_dimension = mim.applies_to_matrix_dimension
if not isinstance(
applies_to_matrix_dimension,
collections.Iterable
Iterable
):
applies_to_matrix_dimension = (int(applies_to_matrix_dimension),)
return applies_to_matrix_dimension
Expand Down
8 changes: 6 additions & 2 deletions nibabel/externals/oset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

from __future__ import absolute_import

from collections import MutableSet
try:
from collections.abc import MutableSet
except ImportError:
# PY2 compatibility
from collections import MutableSet

KEY, PREV, NEXT = range(3)

Expand Down Expand Up @@ -82,4 +86,4 @@ def __eq__(self, other):
return set(self) == set(other)

def __del__(self):
self.clear() # remove circular references
self.clear() # remove circular references