-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MAINT: mappingview check for Python 3.4 #8166
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
Conversation
lib/matplotlib/cbook/__init__.py
Outdated
try: | ||
from collections.abc import MappingView | ||
except ImportError: | ||
MappingView = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the except
block only applies to python 2.7, is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote for using collections.MappingView directly then as I think the if MappingView = None is clunky
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Right but I also felt it expressed the intention more clearly.
…On 28 Feb 2017 16:19, "Paul Hobson" ***@***.***> wrote:
***@***.**** approved this pull request.
------------------------------
In lib/matplotlib/cbook/__init__.py
<#8166 (comment)>
:
> @@ -13,6 +13,12 @@
from six.moves import xrange, zip
from itertools import repeat
import collections
+
+try:
+ from collections.abc import MappingView
+except ImportError:
+ MappingView = None
Looks like the except block only applies to python 2.7, is that right?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8166 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEIHBZhTiK-yJZ1nYy5venuZyFMA2Cbks5rhLmEgaJpZM4MNbox>
.
|
@matthew-brett totally. I just wanted to make sure I understood it properly since I don't have a py2.7 installation handy. |
lib/matplotlib/cbook/__init__.py
Outdated
try: | ||
from collections.abc import MappingView | ||
except ImportError: | ||
MappingView = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
Python 3.4 does not automatically import module `abc` into `collections`, causing an error when checking for `collections.abc.MappingView`. Use `collections.MappingView` to work round this difference. At some point Python may deprecate `collections.MappingView` in favor of `collections.abc.MappingView` but we can fix that when it arises.
LGTM (conditional on tests passing). |
It looks like |
Python 3.4 does not autoamatically import module
abc
intocollections
, causing an error when checking forcollections.abc.MappingView
. Do more explicit import ofMappingView
to work round this difference.
See: https://travis-ci.org/MacPython/matplotlib-wheels/jobs/205713297#L582 for
error on Python 3.4.