Skip to content

Fix "from collections import Mapping, MutableMapping" with Python 3.8. #511

@KelSolaar

Description

@KelSolaar

This relates directly to #489 which has unfortunately not been updated by the original contributor.

The takeaway is that for Python 3.8 not breaking our imports we need to change a few imports from:

from collections import Mapping, MutableMapping

to:

from collections.abc import Mapping, MutableMapping

So I'm suggesting we use the following import scheme:

import sys

if sys.version_info[:2] >= (3, 8):  # pragma: no cover
    from collections.abc import Mapping, MutableMapping
else:  # pragma: no cover
    from collections import Mapping, MutableMapping

These are the imports I noted that would need change when I looked at it a few weeks ago:

/colour-science/colour/colour/algebra
    interpolation.py
        from collections import OrderedDict, Mapping
/colour-science/colour/colour/continuous
    multi_signals.py
        from collections import Iterator, Mapping, OrderedDict, Sequence
    signal.py
        from collections import Iterator, Mapping, OrderedDict, Sequence
/colour-science/colour/colour/plotting
    models.py
        from collections import Mapping
/colour-science/colour/colour/utilities
    array.py
        from collections import Mapping
    data_structures.py
        from collections import Mapping, MutableMapping

We cannot really check if the code works on 3.8 as we don't build against it but I'm assuming this should work.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions