Skip to content
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

Merged
merged 7 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ repos:
- id: mypy
exclude: docs|tests
args: ["--pretty"]
- id: mypy
name: mypy, for Python 2
exclude: noxfile.py|tools/automation/release|docs|tests
args: ["--pretty", "-2"]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.6.0
Expand Down
2 changes: 1 addition & 1 deletion docs/html/development/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ To run tests without parallelization, run:
$ tox -e py36

The example above runs tests against Python 3.6. You can also use other
versions like ``py27`` and ``pypy3``.
versions like ``py39`` and ``pypy3``.

``tox`` has been configured to forward any additional arguments it is given to
``pytest``. This enables the use of pytest's `rich CLI`_. As an example, you
Expand Down
1 change: 0 additions & 1 deletion docs/html/development/release-process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,3 @@ order to create one of these the changes should already be merged into the
.. _`get-pip repository`: https://github.com/pypa/get-pip
.. _`psf-salt repository`: https://github.com/python/psf-salt
.. _`CPython`: https://github.com/python/cpython
.. _`CPython 2.7 EOL date`: https://www.python.org/doc/sunset-python-2/
2 changes: 1 addition & 1 deletion docs/html/reference/pip_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ Since version 6.0, pip also supports specifiers containing `environment markers

::

SomeProject ==5.4 ; python_version < '2.7'
SomeProject ==5.4 ; python_version < '3.8'
SomeProject; sys_platform == 'win32'

Since version 19.1, pip also supports `direct references
Expand Down
8 changes: 4 additions & 4 deletions docs/html/reference/pip_uninstall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Examples

$ python -m pip uninstall simplejson
Uninstalling simplejson:
/home/me/env/lib/python2.7/site-packages/simplejson
/home/me/env/lib/python2.7/site-packages/simplejson-2.2.1-py2.7.egg-info
/home/me/env/lib/python3.9/site-packages/simplejson
/home/me/env/lib/python3.9/site-packages/simplejson-2.2.1-py3.9.egg-info
Proceed (y/n)? y
Successfully uninstalled simplejson

Expand All @@ -52,7 +52,7 @@ Examples

C:\> py -m pip uninstall simplejson
Uninstalling simplejson:
/home/me/env/lib/python2.7/site-packages/simplejson
/home/me/env/lib/python2.7/site-packages/simplejson-2.2.1-py2.7.egg-info
/home/me/env/lib/python3.9/site-packages/simplejson
/home/me/env/lib/python3.9/site-packages/simplejson-2.2.1-py3.9.egg-info
Proceed (y/n)? y
Successfully uninstalled simplejson
1 change: 1 addition & 0 deletions news/8802.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Modernise the codebase after Python 2.
4 changes: 1 addition & 3 deletions src/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import sys
import traceback

from pip._vendor.six import PY2

from pip._internal.cli import cmdoptions
from pip._internal.cli.command_context import CommandContextMixIn
from pip._internal.cli.parser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
Expand Down Expand Up @@ -183,7 +181,7 @@ def _main(self, args):
issue=8333,
)

if '2020-resolver' in options.features_enabled and not PY2:
if '2020-resolver' in options.features_enabled:
logger.warning(
"--use-feature=2020-resolver no longer has any effect, "
"since it is now the default dependency resolver in pip. "
Expand Down
5 changes: 2 additions & 3 deletions src/pip/_internal/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from distutils.util import strtobool

from pip._vendor.contextlib2 import suppress
from pip._vendor.six import string_types

from pip._internal.cli.status_codes import UNKNOWN_ERROR
from pip._internal.configuration import Configuration, ConfigurationError
Expand Down Expand Up @@ -119,7 +118,7 @@ def expand_default(self, option):
help_text = optparse.IndentedHelpFormatter.expand_default(self, option)

if default_values and option.metavar == 'URL':
if isinstance(default_values, string_types):
if isinstance(default_values, str):
default_values = [default_values]

# If its not a list, we should abort and just return the help text
Expand Down Expand Up @@ -275,7 +274,7 @@ def get_default_values(self):
defaults = self._update_defaults(self.defaults.copy()) # ours
for option in self._get_all_options():
default = defaults.get(option.dest)
if isinstance(default, string_types):
if isinstance(default, str):
opt_str = option.get_opt_string()
defaults[option.dest] = option.check_value(opt_str, default)
return optparse.Values(defaults)
Expand Down
7 changes: 3 additions & 4 deletions src/pip/_internal/cli/progress_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sys
from signal import SIGINT, default_int_handler, signal

from pip._vendor import six
from pip._vendor.progress.bar import Bar, FillingCirclesBar, IncrementalBar
from pip._vendor.progress.spinner import Spinner

Expand Down Expand Up @@ -36,16 +35,16 @@ def _select_progress_class(preferred, fallback):
# Collect all of the possible characters we want to use with the preferred
# bar.
characters = [
getattr(preferred, "empty_fill", six.text_type()),
getattr(preferred, "fill", six.text_type()),
getattr(preferred, "empty_fill", str()),
getattr(preferred, "fill", str()),
]
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
characters += list(getattr(preferred, "phases", []))

# Try to decode the characters we're using for the bar using the encoding
# of the given file, if this works then we'll assume that we can use the
# fancier bar and if not we'll fall back to the plaintext bar.
try:
six.text_type().join(characters).encode(encoding)
str().join(characters).encode(encoding)
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
except UnicodeEncodeError:
return fallback
else:
Expand Down
10 changes: 0 additions & 10 deletions src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import os
from functools import partial

from pip._vendor.six import PY2

from pip._internal.cli import cmdoptions
from pip._internal.cli.base_command import Command
from pip._internal.cli.command_context import CommandContextMixIn
Expand Down Expand Up @@ -200,14 +198,6 @@ def __init__(self, *args, **kw):
def determine_resolver_variant(options):
# type: (Values) -> str
"""Determines which resolver should be used, based on the given options."""
# We didn't want to change things for Python 2, since it's nearly done with
# and we're using performance improvements that only work on Python 3.
if PY2:
if '2020-resolver' in options.features_enabled:
return "2020-resolver"
else:
return "legacy"

if "legacy-resolver" in options.deprecated_features_enabled:
return "legacy"

Expand Down
6 changes: 2 additions & 4 deletions src/pip/_internal/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import json
import logging

from pip._vendor import six

from pip._internal.cli import cmdoptions
from pip._internal.cli.req_command import IndexGroupCommand
from pip._internal.cli.status_codes import SUCCESS
Expand Down Expand Up @@ -315,13 +313,13 @@ def format_for_json(packages, options):
for dist in packages:
info = {
'name': dist.project_name,
'version': six.text_type(dist.version),
'version': str(dist.version),
}
if options.verbose >= 1:
info['location'] = dist.location
info['installer'] = get_installer(dist)
if options.outdated:
info['latest_version'] = six.text_type(dist.latest_version)
info['latest_version'] = str(dist.latest_version)
info['latest_filetype'] = dist.latest_filetype
data.append(info)
return json.dumps(data)
3 changes: 1 addition & 2 deletions src/pip/_internal/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
A single word describing where the configuration key-value pair came from
"""

import configparser
import locale
import logging
import os
import sys

from pip._vendor.six.moves import configparser

from pip._internal.exceptions import (
ConfigurationError,
ConfigurationFileCouldNotBeLoaded,
Expand Down
6 changes: 1 addition & 5 deletions src/pip/_internal/distributions/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import abc

from pip._vendor.six import add_metaclass

from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
Expand All @@ -13,8 +11,7 @@
from pip._internal.req import InstallRequirement


@add_metaclass(abc.ABCMeta)
class AbstractDistribution(object):
class AbstractDistribution(object, metaclass=abc.ABCMeta):
"""A base class for handling installable artifacts.

The requirements for anything installable are as follows:
Expand All @@ -29,7 +26,6 @@ class AbstractDistribution(object):
- we must be able to create a Distribution object exposing the
above metadata.
"""

def __init__(self, req):
# type: (InstallRequirement) -> None
super(AbstractDistribution, self).__init__()
Expand Down
13 changes: 3 additions & 10 deletions src/pip/_internal/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,18 @@

from itertools import chain, groupby, repeat

from pip._vendor.six import iteritems

from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
import configparser
from hashlib import _Hash
from typing import Any, Dict, List, Optional, Text

from pip._vendor.pkg_resources import Distribution
from pip._vendor.requests.models import Request, Response
from pip._vendor.six import PY3
from pip._vendor.six.moves import configparser

from pip._internal.req.req_install import InstallRequirement

if PY3:
from hashlib import _Hash
else:
from hashlib import _hash as _Hash


class PipError(Exception):
"""Base pip exception"""
Expand Down Expand Up @@ -346,7 +339,7 @@ def hash_then_or(hash_name):
return chain([hash_name], repeat(' or'))

lines = [] # type: List[str]
for hash_name, expecteds in iteritems(self.allowed):
for hash_name, expecteds in self.allowed.items():
prefix = hash_then_or(hash_name)
lines.extend((' Expected {} {}'.format(next(prefix), e))
for e in expecteds)
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/index/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import os
import re
from collections import OrderedDict
from urllib import parse as urllib_parse
from urllib import request as urllib_request

from pip._vendor import html5lib, requests
from pip._vendor.distlib.compat import unescape
from pip._vendor.requests.exceptions import RetryError, SSLError
from pip._vendor.six.moves.urllib import parse as urllib_parse
from pip._vendor.six.moves.urllib import request as urllib_request

from pip._internal.exceptions import NetworkConnectionError
from pip._internal.models.link import Link
Expand Down
6 changes: 1 addition & 5 deletions src/pip/_internal/models/direct_url.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
""" PEP 610 """
import json
import re

from pip._vendor import six
from pip._vendor.six.moves.urllib import parse as urllib_parse
from urllib import parse as urllib_parse

from pip._internal.utils.typing import MYPY_CHECK_RUNNING

Expand Down Expand Up @@ -35,8 +33,6 @@ def _get(d, expected_type, key, default=None):
if key not in d:
return default
value = d[key]
if six.PY2 and expected_type is str:
expected_type = six.string_types # type: ignore
if not isinstance(value, expected_type):
raise DirectUrlValidationError(
"{!r} has unexpected type for {} (expected {})".format(
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/models/index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pip._vendor.six.moves.urllib import parse as urllib_parse
from urllib import parse as urllib_parse


class PackageIndex(object):
Expand Down
3 changes: 1 addition & 2 deletions src/pip/_internal/models/link.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import posixpath
import re

from pip._vendor.six.moves.urllib import parse as urllib_parse
from urllib import parse as urllib_parse

from pip._internal.utils.filetypes import WHEEL_EXTENSION
from pip._internal.utils.misc import (
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/models/search_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import logging
import os
import posixpath
from urllib import parse as urllib_parse

from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.six.moves.urllib import parse as urllib_parse

from pip._internal.models.index import PyPI
from pip._internal.utils.compat import has_tls
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/network/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"""

import logging
from urllib import parse as urllib_parse

from pip._vendor.requests.auth import AuthBase, HTTPBasicAuth
from pip._vendor.requests.utils import get_netrc_auth
from pip._vendor.six.moves.urllib import parse as urllib_parse

from pip._internal.utils.misc import (
ask,
Expand Down
1 change: 0 additions & 1 deletion src/pip/_internal/network/lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from zipfile import BadZipfile, ZipFile

from pip._vendor.requests.models import CONTENT_CHUNK_SIZE
from pip._vendor.six.moves import range

from pip._internal.network.utils import HEADERS, raise_for_status, response_chunks
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/network/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import platform
import sys
import warnings
from urllib import parse as urllib_parse

from pip._vendor import requests, six, urllib3
from pip._vendor.cachecontrol import CacheControlAdapter
from pip._vendor.requests.adapters import BaseAdapter, HTTPAdapter
from pip._vendor.requests.models import Response
from pip._vendor.requests.structures import CaseInsensitiveDict
from pip._vendor.six.moves.urllib import parse as urllib_parse
from pip._vendor.urllib3.exceptions import InsecureRequestWarning

from pip import __version__
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/network/xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"""

import logging
from urllib import parse as urllib_parse

# NOTE: XMLRPC Client is not annotated in typeshed as on 2017-07-17, which is
# why we ignore the type on this import
from pip._vendor.six.moves import xmlrpc_client # type: ignore
from pip._vendor.six.moves.urllib import parse as urllib_parse

from pip._internal.exceptions import NetworkConnectionError
from pip._internal.network.utils import raise_for_status
Expand Down
3 changes: 1 addition & 2 deletions src/pip/_internal/operations/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
import os

from pip._vendor import six
from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.pkg_resources import RequirementParseError

Expand Down Expand Up @@ -162,7 +161,7 @@ def freeze(

# Warn about requirements that were included multiple times (in a
# single requirements file or in different requirements files).
for name, files in six.iteritems(req_files):
for name, files in req_files.items():
if len(files) > 1:
logger.warning("Requirement %s included multiple times [%s]",
name, ', '.join(sorted(set(files))))
Expand Down
Loading