Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 4 commits into from
Oct 31, 2017
Merged

Remove redundant Python 2 code #10865

merged 4 commits into from
Oct 31, 2017

Conversation

hugovk
Copy link
Contributor

@hugovk hugovk commented Oct 21, 2017

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:

  • Restore trailing whitespace
  • Restore cast_unicode
  • Resolve merge conflict
  • Restore clr import
  • Restore arg_split import
  • Keep cast_bytes in py3compat
  • Restore all non-Python 2 stuff in py3compat
  • Add deprecation docstring to py3compat

@takluyver
Copy link
Member

I haven't checked in detail, but I'm not 100% comfortable removing all those cast_unicode calls. We have a cast_unicode_py2 function for when we know it's redundant on Python 3, so if we're using cast_unicode instead, there's a chance that that is necessary even on Python 3.

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 git blame.

@hugovk
Copy link
Contributor Author

hugovk commented Oct 23, 2017

Sure, coming up.

@hugovk hugovk force-pushed the rm-python2 branch 3 times, most recently from a7e65e3 to f05ac36 Compare October 23, 2017 12:09
@hugovk
Copy link
Contributor Author

hugovk commented Oct 23, 2017

@takluyver This PR updated.

@takluyver takluyver added this to the 6.3 milestone Oct 24, 2017
@@ -0,0 +1,19 @@
# Top-most EditorConfig file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Carreau @gnestor thoughts on adding this file? It seems reasonable to me, but I know people sometimes take issue with ever more config files in the repo root directory.

Copy link
Member

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.

@@ -12,23 +12,21 @@
"""

# Import cli libraries:
import clr
Copy link
Member

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.

import System

# Import Python libraries:
import os

# Import IPython libraries:
from IPython.utils import py3compat
from ._process_common import arg_split
Copy link
Member

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.

def cast_bytes(s, encoding=None):
if not isinstance(s, bytes):
return encode(s, encoding)
return s
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

@takluyver
Copy link
Member

Thanks, this mostly looks good now. A few comments inline.

@takluyver
Copy link
Member

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 py3compat that were there before (not just the one my previous comment was on the line of) :-)

@Carreau
Copy link
Member

Carreau commented Oct 24, 2017

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
Copy link
Member

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 ?

Copy link
Contributor Author

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.

Copy link
Member

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
Copy link
Member

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 ?

Copy link
Member

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:

  1. Eliminate all remaining usage of it in IPython
  2. Add a deprecation warning when it's loaded
  3. (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])?'
Copy link
Member

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 ?

Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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.

@Carreau
Copy link
Member

Carreau commented Oct 24, 2017

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.

@takluyver
Copy link
Member

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.

@hugovk
Copy link
Contributor Author

hugovk commented Oct 25, 2017

Updated to:

  • retain all of py3compat.py as is, except for the if/else that only runs on Python 2
  • update py3compat.py docstring to note it is deprecated and will be removed in a future version
  • update pycompat.rst to note it will be removed in a future version
  • delete unused tox.ini

@takluyver
Copy link
Member

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.

@takluyver takluyver merged commit 5b2b7dd into ipython:master Oct 31, 2017
@takluyver
Copy link
Member

Thanks @hugovk !

@hugovk hugovk deleted the rm-python2 branch October 31, 2017 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants