-
Notifications
You must be signed in to change notification settings - Fork 274
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
Add a six.moves for collections and collections.abc in preparation fo… #241
Conversation
@benjaminp could you please take a look at this PR? |
This would be very helpful to use six for improving compatibility with the upcoming Python 3.7 |
six.py
Outdated
@@ -300,6 +300,7 @@ class _MovedItems(_LazyModule): | |||
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"), | |||
MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"), | |||
MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"), | |||
MovedModule("collections_abc", "collections", "collections.abc", sys.version_info[0:2] >= (3, 3)), |
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.
Why not just sys.version_info >= (3, 3)
instead of sys.version_info[0:2] >= (3, 3)
?
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.
Consistency with the PYX variables at file's beginning
six.py
Outdated
@@ -102,9 +102,9 @@ def __get__(self, obj, tp): | |||
|
|||
class MovedModule(_LazyDescr): | |||
|
|||
def __init__(self, name, old, new=None): | |||
def __init__(self, name, old, new=None, use_new=True): |
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.
How does this help?
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.
Sorry, I see now. Perhaps you should pass use_new in by name to make the code below clear.
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.
Would it be better to parametrise by "version_changed" and do the comparison here?
Or leave it all on the call side, but use
MovedModule("collections_abc", "collections", "collections.abc" if sys.version_info[0:2] >= (3, 3) else "collections")
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.
Let's wait to see what @benjaminp says before we change anything, I only use that parameter because any Python 3 version below 3.3 doesn't include the "abc" submodule.
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.
Alternatively to a boolean use_new
one could add an argument that specifies from which version on the new behavior should be used, e.g. since='3.3'
or new_since='3.3'
.
Since six deals with the Python 2/3 boundary, this request seems misplaced, unless the project seeks to expand its scope for general cross-version compatibility. |
Python 3.8 is slated to remove support for ABCs in the collections module.
…On Tue, Jul 3, 2018, 3:37 PM Jason R. Coombs, ***@***.***> wrote:
Since six deals with the Python 2/3 boundary, this request seems
misplaced, unless the project seeks to expand its scope for general
cross-version compatibility.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#241 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AExYE9xgP2PYQBSdKkAZnc6ujjiGm5_Wks5uC8gDgaJpZM4T6v3a>
.
|
@jaraco: if not making this change forces libraries to either use hacks or drop Python 2 support (when otherwise they support Py>=3.4), then surely it's within six's scope. |
…1431) Closes #11121 This PR removes the deprecation warning about ABC being moved from `collections` to `collections.abc` when importing scikit-learn in Python 3.7. In the end, I put `collections.abc.{Sequence, Iterable, Mapping, Sized}` in the namespace of `sklearn.utils.fixes`. This was the simplest way I could find, and while it has the drawback of obfuscating the real module name, other approached appeared more problematic and a similar approach is currently used e.g. for `utils.fixes.signature` which is an alias for `inspect.signature`. We can't just patch six with benjaminp/six#241, because sklearn uses six from 5 years ago, which would need updating and I'm not sure if it could have side effects (e.g. for pickling backward compatibility etc). **Edit**: This adds a test checking that generally no warnings are raised when importing scikit-learn top-level modules.
…ikit-learn#11431) Closes scikit-learn#11121 This PR removes the deprecation warning about ABC being moved from `collections` to `collections.abc` when importing scikit-learn in Python 3.7. In the end, I put `collections.abc.{Sequence, Iterable, Mapping, Sized}` in the namespace of `sklearn.utils.fixes`. This was the simplest way I could find, and while it has the drawback of obfuscating the real module name, other approached appeared more problematic and a similar approach is currently used e.g. for `utils.fixes.signature` which is an alias for `inspect.signature`. We can't just patch six with benjaminp/six#241, because sklearn uses six from 5 years ago, which would need updating and I'm not sure if it could have side effects (e.g. for pickling backward compatibility etc). **Edit**: This adds a test checking that generally no warnings are raised when importing scikit-learn top-level modules.
…r Python 3.7+ (Closes #155)
@timhoffm I decided to use your suggestion of adding a "since" version variable. |
six.py
Outdated
super(MovedModule, self).__init__(name) | ||
if PY3: | ||
if sys.version_info[0:len(since)] >= since: |
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.
The 0 can be left out.
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.
As well as slicing at all.
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.
You can suggest changes via GH now :)
if sys.version_info[0:len(since)] >= since: | |
if sys.version_info >= since: |
six.py
Outdated
@@ -300,6 +300,7 @@ class _MovedItems(_LazyModule): | |||
MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"), | |||
MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"), | |||
MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"), | |||
MovedModule("collections_abc", "collections", "collections.abc", (3, 3)), |
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 would use since as kwarg here to make it more readable.
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.
MovedModule("collections_abc", "collections", "collections.abc", (3, 3)), | |
MovedModule("collections_abc", "collections", "collections.abc", since=(3, 3)), |
Made MovedAttribute class have similar behaviour as MovedModule (future proofing)
Suggested changes have been made, I also decided to future proof MovedAttribute incase it ever becomes required. |
This looks ready to go, and I would appreciate avoiding the deprecation warning with Python 3.7. |
Related CPython PR : python/cpython#10596 |
Can we push this through? This would help with other projects. |
Any way to help move this along? |
My initial reaction is similar to jaraco's. The planned release date for Python 3.8 is two months before Python 2's EoL. Note the CPython PR to actually remove |
@benjaminp Is there a compatibility library for changes between Python versions 2 and 3.8? There needs to be one for the same reason that six was needed. Why not have six do this? (Edited: I meant from Python 2 to Python 3.8.) |
For compatibility between Python 3 versions you have to just import from |
@serhiy-storchaka You're right. Unfortunately, many projects need to support Python 2, which has no |
There isn't, probably because many of the compatibility issues are selective (only between particular versions of Python), such as packages in the |
Back in the Python 2 days, I used to maintain a project called jaraco.compat that would provide forward-compatibility (backports) of various language features. Perhaps that project could be revived to support small compatibilities like this one. |
I'm rolling out jaraco.compat 2.2 with |
Is there anything blocking this? Was surprised to find that there was no option in six to avoid: if six.PY3:
from collections.abc import Iterable, Sequence
else:
from collections import Iterable, Sequence |
If you want a one-liner, use
|
@jaraco The problem is that a lot of projects don't want to add another dependency. I don't see why this isn't in six. |
…r Python 3.7+ (Closes #155)