-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Remove redundant Python 2 code #10865
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
I haven't checked in detail, but I'm not 100% comfortable removing all those Also, as with your PR to my fork, can we ask you to do it with your editor configured to not strip whitespace? It can cause merge conflicts and problems with |
Sure, coming up. |
a7e65e3
to
f05ac36
Compare
@takluyver This PR updated. |
@@ -0,0 +1,19 @@ | |||
# Top-most EditorConfig file |
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.
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'm ok adding it, but I don't know of a lot of people using that. It may likely just rot as the tox.ini file which is never used and still test on Python 27 as shown further in this PR.
IPython/utils/_process_cli.py
Outdated
@@ -12,23 +12,21 @@ | |||
""" | |||
|
|||
# Import cli libraries: | |||
import clr |
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 think this might be a special thing that needs to be imported first for IronPython to work. Best to leave this module alone, I think.
IPython/utils/_process_cli.py
Outdated
import System | ||
|
||
# Import Python libraries: | ||
import os | ||
|
||
# Import IPython libraries: | ||
from IPython.utils import py3compat | ||
from ._process_common import arg_split |
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.
This is there to be re-exposed by the module. Again, let's leave this as is.
IPython/utils/py3compat.py
Outdated
def cast_bytes(s, encoding=None): | ||
if not isinstance(s, bytes): | ||
return encode(s, encoding) | ||
return s |
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'm a bit wary of removing things from py3compat
in case other modules like ipykernel
rely on them.
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.
Sure, I'll make these changes. Seeing as Python 3 is now the only supported version, how about somehow marking py3compat
as deprecated?
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.
We can mark it as deprecated once we are not using it anymore. If we mark it as deprecated and still use it here and there people complain we don't even follow our own deprecations.
Thanks, this mostly looks good now. A few comments inline. |
Yeah, I think it could have a 'deprecated' note in the docstring now, and then in the future when we think we've got rid of all uses of it, add a warning on import. For now, let's leave all the functions exposed by |
First thing I want to say is I'm worried about finishing up cleaning py2 compat code; this has been painful before for automatic backport of bug fixes, and lead to subtle bugs. We've stop removing things on purpose some time ago. I'll look at it in more details. |
@@ -21,5 +21,6 @@ __pycache__ | |||
.DS_Store | |||
\#*# | |||
.#* | |||
.cache |
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.
Should that also be in your system global .gitignore
if you feel the need to add it ?
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.
Perhaps, but it's in the common Python one --https://github.com/github/gitignore/blob/master/Python.gitignore#L43 -- and ignored in some other Python projects I just checked. And it showed up after running the tests for this project (iptest --coverage xml
), so it can show up for others too.
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.
Yeah, I'm not sure exactly what creates it, but I see it quite often when running tests, so I'm fine with adding it to gitignore.
@@ -1,22 +1,17 @@ | |||
# coding: utf-8 |
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.
if we remove the compatibility layer python2/python3, should this file still exists ? The way I see it either this file is / or is not. If there are function with use often they probably should be in utils. @takluyver thoughts ?
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.
Thoughts: leave it in for now, except for the if/else branch that only runs on Py2. Add a deprecation note in the docstring. Then, over a succession of future releases:
- Eliminate all remaining usage of it in IPython
- Add a deprecation warning when it's loaded
- (Eventually) get rid of it
It doesn't cost much to leave it sitting around unused for a while, and other code might be importing it. We did document it in earlier versions, though the current version tells people not to rely on it.
StringPrefix = r'(?:[bB][rR]?|[rR][bB]?|[uU])?' | ||
else: | ||
StringPrefix = r'(?:[bB]?[rR]?)?' | ||
StringPrefix = r'(?:[bB][rR]?|[rR][bB]?|[uU])?' |
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.
if I remember correctly this file is base on Python 3.2 stdlib, does it make sens to check whether the bugs have been fixed upstream on 3.4+ instead of having it diverge more ?
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 suspect this change is reverting a divergence that was previously introduced. Ultimately it would be good to get rid of it, but that's a more complex job for another day.
exec(compile(open(fname).read(), fname, "exec"), globs, locs) | ||
def execfile(fname, globs, locs=None): | ||
locs = locs or globs | ||
exec(compile(open(fname).read(), fname, "exec"), globs, locs) |
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.
+1
tox.ini
Outdated
@@ -19,7 +19,7 @@ toxworkdir = /tmp/tox_ipython | |||
; Other IPython/testing dependencies should be in setup.py, not here | |||
deps = | |||
pypy: https://bitbucket.org/pypy/numpy/get/master.zip | |||
py{36,35,34,33,27}: matplotlib | |||
py{36,35,34,33}: matplotlib |
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.
Considering if we should just remove the .tox
file as it is never used.
I don't have much to say, we'll need to do that at some point (and that will simplify the code. My guts guts just make me worried that there will be subtle bugs, and that it may create conflicts later. I've been willing to start a 7.x branch at some point; and would be more comfortable to get that into a major release than a minor. @takluyver thoughts ? You've been more active than me on IPython in the last few weeks. |
I think that if we make this a bit more conservative, it's fine for a 6.x release. I already had a look over it and I'm happy with most of the changes. The main thing is that I'd preserve the py3compat API at least through the 6.x series, and probably longer. |
Updated to:
|
This looks OK to me as it stands. I'm sure someone will complain about removing tox.ini, but it's evidently not in use, or people would have already removed Python 2 from the list. So I'd say that not having it is better than having it inaccurate. |
Thanks @hugovk ! |
IPython 6 dropped support for Python 2.7, 3.0, 3.1 and 3.2 (eg. #9145, #9900, #10131).
This removes a lot of old Python 2 code still in the codebase.
TODO:
cast_unicode
clr
importarg_split
importcast_bytes
inpy3compat
py3compat
py3compat