Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
MAINT: mappingview check for Python 3.4 #8166
Conversation
| +try: | ||
| + from collections.abc import MappingView | ||
| +except ImportError: | ||
| + MappingView = None |
anntzer
Mar 1, 2017
Contributor
2.7 has mappingview (https://docs.python.org/2.7/library/collections.html#collections.MappingView) so I don't know when it can ever be triggered.
(My guess is that below, the test on whether we're running Py3 should just be removed -- we may as well sanitize the case where someone passes dic.itervalues() on Py2 too (well I always thought the whole idea was misguided but let's at least be consistent across Python versions.))
matthew-brett
Mar 1, 2017
Contributor
So - collections.MappingView is present in all Python versions we support, but collections.abc.MappingView is present only for the Python 3 versions:
Changed in version 3.3: Moved Collections Abstract Base Classes to the collections.abc module. For backwards compatibility, they continue to be visible in this module as well.
https://docs.python.org/3.5/library/collections.html#module-collections
We could use collections.MappingView directly, they haven't been deprecated, I guess.
story645
Mar 1, 2017
Member
I vote for using collections.MappingView directly then as I think the if MappingView = None is clunky
phobson
changed the title from
MAINT: mappingview check for Python 3.4 to [MRG+1] MAINT: mappingview check for Python 3.4
Mar 1, 2017
|
Right but I also felt it expressed the intention more clearly.
…
|
|
@matthew-brett totally. I just wanted to make sure I understood it properly since I don't have a py2.7 installation handy. |
| +try: | ||
| + from collections.abc import MappingView | ||
| +except ImportError: | ||
| + MappingView = None |
anntzer
Mar 1, 2017
Contributor
2.7 has mappingview (https://docs.python.org/2.7/library/collections.html#collections.MappingView) so I don't know when it can ever be triggered.
(My guess is that below, the test on whether we're running Py3 should just be removed -- we may as well sanitize the case where someone passes dic.itervalues() on Py2 too (well I always thought the whole idea was misguided but let's at least be consistent across Python versions.))
|
Side question: Codecov says this line is covered, so how was that never caught before in the CI? (Unfortunately Travis doesn't want to load for me right now.) |
|
I'm just guessing, but I suspect that some versions of Python 3.4 do an automatic import of
That's just a guess, because the behavior above is so for all the Python3.4s I could find. |
|
LGTM (conditional on tests passing). |
tacaswell
added this to the
2.0.1 (next bug fix release)
milestone
Mar 1, 2017
dstansby
changed the title from
[MRG+1] MAINT: mappingview check for Python 3.4 to MAINT: mappingview check for Python 3.4
Mar 1, 2017
dstansby
merged commit c2f675d
into matplotlib:master
Mar 1, 2017
4 of 5 checks passed
|
It looks like |
matthew-brett commentedFeb 27, 2017
Python 3.4 does not autoamatically import module
abcintocollections, causing an error when checking forcollections.abc.MappingView. Do more explicit import ofMappingViewto work round this difference.
See: https://travis-ci.org/MacPython/matplotlib-wheels/jobs/205713297#L582 for
error on Python 3.4.