-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Remove redundant Python 2.7 code #9335
Conversation
The |
For example, with: diff --git a/src/pip/_internal/resolution/resolvelib/found_candidates.py b/src/pip/_internal/resolution/resolvelib/found_candidates.py
index a669e8936..db40bf86b 100644
--- a/src/pip/_internal/resolution/resolvelib/found_candidates.py
+++ b/src/pip/_internal/resolution/resolvelib/found_candidates.py
@@ -1,7 +1,7 @@
import itertools
import operator
-from pip._vendor.six.moves import collections_abc # type: ignore
+import collections.abc # type: ignore
from pip._internal.utils.compat import lru_cache
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
@@ -46,7 +46,7 @@ def _insert_installed(installed, others):
return iter(candidates)
-class FoundCandidates(collections_abc.Sequence):
+class FoundCandidates(collections.abc.Sequence):
"""A lazy sequence to provide candidates to the resolver.
The intended usage is to return this from `find_matches()` so the resolver I get: $ pre-commit run --all-files mypy
mypy.....................................................................Failed
- hook id: mypy
- exit code: 1
src/pip/_internal/resolution/resolvelib/found_candidates.py:49: error:
Missing
type
parameters
for
generic
type
"Sequence"
...ass FoundCandidates(collections.abc.Seque...
^
src/pip/_internal/resolution/resolvelib/found_candidates.py:67: error:
Signature
of
"__getitem__"
incompatible
with
supertype
"Sequence"
def __getitem__(self, index):
^ |
Ah OK, this one’s special because on Python 3 we need to use protocol to satisfy Mypy. But let’s not touch code for the new resolver for now, since there are more likely fixes we need to backport to 20.3 before 21.0 can drop, and adding converting code there would make backporting difficult. |
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.
Thanks a lot for picking this up! <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.
Thanks for the quick response! This is ready to go IMO, but a few inline nitpicks below. Feel free to ignore 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.
🎉
src/pip/_internal/utils/compat.py
Outdated
Returns a tuple (x, y) representing the width(x) and the height(y) | ||
in characters of the terminal window. | ||
""" | ||
return tuple(shutil.get_terminal_size()) # type: ignore |
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.
shutil.get_terminal_size()
already returns a tuple. Perhaps this compat shim could be removed entirely?
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.
IIRC this was to work around a Typeshed declaration bug. That was fixed upstream since linting jobs are passing without issues.
shlex.quote(str(arg)) if isinstance(arg, HiddenText) | ||
else shlex.quote(arg) for arg in args |
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 comment above this code is partially outdated now and perhaps the solution is too. Thoughts on?
shlex.quote(str(arg)) if isinstance(arg, HiddenText) | |
else shlex.quote(arg) for arg in args | |
shlex.quote(str(arg)) for arg in args |
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.
Suggestion makes sense based on the comment. What do the maintainers think (who may have more context)?
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 suggestion looks good for me. In retrospect, we could have implemented __unicode__
on HiddenText
and used six.text_type
here (it would make the intent more obvious), but that’s all history now.
@@ -166,7 +158,7 @@ def tmpdir(request, tmpdir): | |||
# py.path.remove() uses str paths on Python 2 and cannot | |||
# handle non-ASCII file names. This works around the problem by | |||
# passing a unicode object to rmtree(). | |||
shutil.rmtree(six.text_type(tmpdir), ignore_errors=True) | |||
shutil.rmtree(str(tmpdir), ignore_errors=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.
The comment above this line is outdated and perhaps the solution.
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 maybe just shutil.rmtree(tmpdir, ignore_errors=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.
I think either that or simply tmpdir.remove()
.
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.
tmpdir.remove(ignore_errors=True)
, rather.
u"pip = pip._internal.main:pip", | ||
u"pip:pip = pip._internal.main:pip", | ||
pytest.param(u"進入點 = 套件.模組:函式", marks=skip_if_python2), | ||
u"進入點 = 套件.模組:函式", |
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 u-prefix could be dropped. That work could also be handled separately if preferred.
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, this could be done with pyupgrade.
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'll get to that after this, I imagine.
Without Python 2 support, the wheel is not universal. diff --git a/setup.cfg b/setup.cfg
index 84a959a32..10210196d 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -101,8 +101,5 @@ exclude_lines =
# Can be set to exclude e.g. `if PY2:` on Python 3
${PIP_CI_COVERAGE_EXCLUDES}
-[bdist_wheel]
-universal = 1
-
[metadata]
license_file = LICENSE.txt Edit: Done in #9339 |
Co-authored-by: Jon Dufresne <[email protected]>
I think this PR is mergable as is, and we can iterate on this stuff as we move forward. :) |
🌱 |
For #8802.
This removes some redundant code now that Python 2.7 is no longer supported.
The bulk removes most of the use of six, except for these where I couldn't figure out the type ignores on the replacements:
And also
ensure_binary, ensure_text, ensure_str, reraise
, perhaps these should be copied (and simplified) as utility functions?I also didn't touch any
src/pip/_vendor
code.There's definitely more Python 2 stuff that can be removed, but I didn't want this big PR to get any bigger.