mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Merge pull request #6089 from pradyunsg/mypy/fix-issues
Fixes for various mypy related issues
This commit is contained in:
commit
b38e835ab2
|
@ -53,8 +53,7 @@ if MYPY_CHECK_RUNNING:
|
|||
)
|
||||
from pip._internal.models.link import Link # noqa: F401
|
||||
from pip._internal.utils.hashes import Hashes # noqa: F401
|
||||
# cannot import alias directly here, fixed in mypy==0.641
|
||||
import pip._internal.vcs as vcs_type_aliases # noqa: F401
|
||||
from pip._internal.vcs import AuthInfo # noqa: F401
|
||||
|
||||
try:
|
||||
import ssl # noqa
|
||||
|
@ -147,7 +146,7 @@ class MultiDomainBasicAuth(AuthBase):
|
|||
def __init__(self, prompting=True):
|
||||
# type: (bool) -> None
|
||||
self.prompting = prompting
|
||||
self.passwords = {} # type: Dict[str, vcs_type_aliases.AuthInfo]
|
||||
self.passwords = {} # type: Dict[str, AuthInfo]
|
||||
|
||||
def __call__(self, req):
|
||||
parsed = urllib_parse.urlparse(req.url)
|
||||
|
|
|
@ -5,6 +5,12 @@ 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:
|
||||
from typing import Optional # noqa: F401
|
||||
from pip._internal.req.req_install import InstallRequirement # noqa: F401
|
||||
|
||||
|
||||
class PipError(Exception):
|
||||
"""Base pip exception"""
|
||||
|
@ -96,7 +102,7 @@ class HashError(InstallationError):
|
|||
typically available earlier.
|
||||
|
||||
"""
|
||||
req = None
|
||||
req = None # type: Optional[InstallRequirement]
|
||||
head = ''
|
||||
|
||||
def body(self):
|
||||
|
|
|
@ -706,9 +706,7 @@ class PackageFinder(object):
|
|||
best_candidate = None
|
||||
|
||||
if req.satisfied_by is not None:
|
||||
# type error fixed in mypy==0.641, remove after update
|
||||
installed_version = parse_version(
|
||||
req.satisfied_by.version) # type: ignore
|
||||
installed_version = parse_version(req.satisfied_by.version)
|
||||
else:
|
||||
installed_version = None
|
||||
|
||||
|
@ -988,9 +986,7 @@ def _clean_link(url):
|
|||
"""Makes sure a link is fully encoded. That is, if a ' ' shows up in
|
||||
the link, it will be rewritten to %20 (while not over-quoting
|
||||
% or other characters)."""
|
||||
# type error fixed in mypy==0.641, remove after update
|
||||
return _CLEAN_LINK_RE.sub(
|
||||
lambda match: '%%%2x' % ord(match.group(0)), url) # type: ignore
|
||||
return _CLEAN_LINK_RE.sub(lambda match: '%%%2x' % ord(match.group(0)), url)
|
||||
|
||||
|
||||
class HTMLPage(object):
|
||||
|
|
|
@ -15,7 +15,7 @@ from pip._internal.utils.compat import WINDOWS, expanduser
|
|||
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
||||
|
||||
if MYPY_CHECK_RUNNING:
|
||||
from typing import Union, Dict, List, Optional # noqa: F401
|
||||
from typing import Any, Union, Dict, List, Optional # noqa: F401
|
||||
|
||||
|
||||
# Application Directories
|
||||
|
@ -163,8 +163,10 @@ def distutils_scheme(dist_name, user=False, home=None, root=None,
|
|||
|
||||
d = Distribution(dist_args)
|
||||
# Ignoring, typeshed issue reported python/typeshed/issues/2567
|
||||
d.parse_config_files() # type: ignore
|
||||
i = d.get_command_obj('install', create=True) # type: ignore
|
||||
d.parse_config_files()
|
||||
# NOTE: Ignoring type since mypy can't find attributes on 'Command'
|
||||
i = d.get_command_obj('install', create=True) # type: Any
|
||||
assert i is not None
|
||||
# NOTE: setting user or home has the side-effect of creating the home dir
|
||||
# or user base for installations during finalize_options()
|
||||
# ideally, we'd prefer a scheme class that has no side-effects.
|
||||
|
|
|
@ -31,7 +31,7 @@ from pip._internal.wheel import Wheel
|
|||
|
||||
if MYPY_CHECK_RUNNING:
|
||||
from typing import ( # noqa: F401
|
||||
Optional, Tuple, Set, Any, Mapping, Union, Text
|
||||
Optional, Tuple, Set, Any, Union, Text, Dict,
|
||||
)
|
||||
from pip._internal.cache import WheelCache # noqa: F401
|
||||
|
||||
|
@ -160,7 +160,7 @@ def install_req_from_editable(
|
|||
comes_from=None, # type: Optional[str]
|
||||
use_pep517=None, # type: Optional[bool]
|
||||
isolated=False, # type: bool
|
||||
options=None, # type: Optional[Mapping[Text, Any]]
|
||||
options=None, # type: Optional[Dict[str, Any]]
|
||||
wheel_cache=None, # type: Optional[WheelCache]
|
||||
constraint=False # type: bool
|
||||
):
|
||||
|
@ -196,7 +196,7 @@ def install_req_from_line(
|
|||
comes_from=None, # type: Optional[Union[str, InstallRequirement]]
|
||||
use_pep517=None, # type: Optional[bool]
|
||||
isolated=False, # type: bool
|
||||
options=None, # type: Optional[Mapping[Text, Any]]
|
||||
options=None, # type: Optional[Dict[str, Any]]
|
||||
wheel_cache=None, # type: Optional[WheelCache]
|
||||
constraint=False # type: bool
|
||||
):
|
||||
|
|
|
@ -68,7 +68,7 @@ SUPPORTED_OPTIONS_REQ = [
|
|||
] # type: List[Callable[..., optparse.Option]]
|
||||
|
||||
# the 'dest' string values
|
||||
SUPPORTED_OPTIONS_REQ_DEST = [o().dest for o in SUPPORTED_OPTIONS_REQ]
|
||||
SUPPORTED_OPTIONS_REQ_DEST = [str(o().dest) for o in SUPPORTED_OPTIONS_REQ]
|
||||
|
||||
|
||||
def parse_requirements(
|
||||
|
@ -161,20 +161,17 @@ def process_line(
|
|||
"""
|
||||
parser = build_parser(line)
|
||||
defaults = parser.get_default_values()
|
||||
# fixed in mypy==0.650
|
||||
defaults.index_url = None # type: ignore
|
||||
defaults.index_url = None
|
||||
if finder:
|
||||
# `finder.format_control` will be updated during parsing
|
||||
# fixed in mypy==0.650
|
||||
defaults.format_control = finder.format_control # type: ignore
|
||||
defaults.format_control = finder.format_control
|
||||
args_str, options_str = break_args_options(line)
|
||||
# Prior to 2.7.3, shlex cannot deal with unicode entries
|
||||
if sys.version_info < (2, 7, 3):
|
||||
# Prior to 2.7.3, shlex cannot deal with unicode entries
|
||||
# https://github.com/python/mypy/issues/1174
|
||||
options_str = options_str.encode('utf8') # type: ignore
|
||||
# https://github.com/python/mypy/issues/1174
|
||||
opts, _ = parser.parse_args(shlex.split(options_str), # type: ignore
|
||||
defaults)
|
||||
opts, _ = parser.parse_args(
|
||||
shlex.split(options_str), defaults) # type: ignore
|
||||
|
||||
# preserve for the nested code path
|
||||
line_comes_from = '%s %s (line %s)' % (
|
||||
|
@ -232,8 +229,7 @@ def process_line(
|
|||
|
||||
# percolate hash-checking option upward
|
||||
elif opts.require_hashes:
|
||||
# fixed in mypy==0.650
|
||||
options.require_hashes = opts.require_hashes # type: ignore
|
||||
options.require_hashes = opts.require_hashes
|
||||
|
||||
# set finder options
|
||||
elif finder:
|
||||
|
@ -298,8 +294,8 @@ def build_parser(line):
|
|||
# add offending line
|
||||
msg = 'Invalid requirement: %s\n%s' % (line, msg)
|
||||
raise RequirementsFileParseError(msg)
|
||||
# ignore type, because mypy disallows assigning to a method,
|
||||
# see https://github.com/python/mypy/issues/2427
|
||||
# NOTE: mypy disallows assigning to a method
|
||||
# https://github.com/python/mypy/issues/2427
|
||||
parser.exit = parser_exit # type: ignore
|
||||
|
||||
return parser
|
||||
|
@ -313,10 +309,8 @@ def join_lines(lines_enum):
|
|||
primary_line_number = None
|
||||
new_line = [] # type: List[Text]
|
||||
for line_number, line in lines_enum:
|
||||
# fixed in mypy==0.641
|
||||
if not line.endswith('\\') or COMMENT_RE.match(line): # type: ignore
|
||||
# fixed in mypy==0.641
|
||||
if COMMENT_RE.match(line): # type: ignore
|
||||
if not line.endswith('\\') or COMMENT_RE.match(line):
|
||||
if COMMENT_RE.match(line):
|
||||
# this ensures comments are always matched later
|
||||
line = ' ' + line
|
||||
if new_line:
|
||||
|
@ -343,8 +337,7 @@ def ignore_comments(lines_enum):
|
|||
Strips comments and filter empty lines.
|
||||
"""
|
||||
for line_number, line in lines_enum:
|
||||
# fixed in mypy==0.641
|
||||
line = COMMENT_RE.sub('', line) # type: ignore
|
||||
line = COMMENT_RE.sub('', line)
|
||||
line = line.strip()
|
||||
if line:
|
||||
yield line_number, line
|
||||
|
@ -382,8 +375,7 @@ def expand_env_variables(lines_enum):
|
|||
to uppercase letter, digits and the `_` (underscore).
|
||||
"""
|
||||
for line_number, line in lines_enum:
|
||||
# fixed in mypy==0.641
|
||||
for env_var, var_name in ENV_VAR_RE.findall(line): # type: ignore
|
||||
for env_var, var_name in ENV_VAR_RE.findall(line):
|
||||
value = os.getenv(var_name)
|
||||
if not value:
|
||||
continue
|
||||
|
|
|
@ -42,11 +42,12 @@ from pip._internal.wheel import move_wheel_files
|
|||
|
||||
if MYPY_CHECK_RUNNING:
|
||||
from typing import ( # noqa: F401
|
||||
Optional, Iterable, List, Union, Any, Mapping, Text, Sequence
|
||||
Optional, Iterable, List, Union, Any, Text, Sequence, Dict
|
||||
)
|
||||
from pip._vendor.pkg_resources import Distribution # noqa: F401
|
||||
from pip._internal.index import PackageFinder # noqa: F401
|
||||
from pip._internal.build_env import BuildEnvironment # noqa: F401
|
||||
from pip._internal.cache import WheelCache # noqa: F401
|
||||
from pip._internal.index import PackageFinder # noqa: F401
|
||||
from pip._vendor.pkg_resources import Distribution # noqa: F401
|
||||
from pip._vendor.packaging.specifiers import SpecifierSet # noqa: F401
|
||||
from pip._vendor.packaging.markers import Marker # noqa: F401
|
||||
|
||||
|
@ -72,7 +73,7 @@ class InstallRequirement(object):
|
|||
markers=None, # type: Optional[Marker]
|
||||
use_pep517=None, # type: Optional[bool]
|
||||
isolated=False, # type: bool
|
||||
options=None, # type: Optional[Mapping[Text, Any]]
|
||||
options=None, # type: Optional[Dict[str, Any]]
|
||||
wheel_cache=None, # type: Optional[WheelCache]
|
||||
constraint=False, # type: bool
|
||||
extras=() # type: Iterable[str]
|
||||
|
@ -130,7 +131,7 @@ class InstallRequirement(object):
|
|||
self.is_direct = False
|
||||
|
||||
self.isolated = isolated
|
||||
self.build_env = NoOpBuildEnvironment()
|
||||
self.build_env = NoOpBuildEnvironment() # type: BuildEnvironment
|
||||
|
||||
# For PEP 517, the directory where we request the project metadata
|
||||
# gets stored. We need this to pass to build_wheel, so the backend
|
||||
|
@ -876,9 +877,7 @@ class InstallRequirement(object):
|
|||
dir_arcname = self._get_archive_name(dirname,
|
||||
parentdir=dirpath,
|
||||
rootdir=dir)
|
||||
# should be fixed in mypy==0.650
|
||||
# see https://github.com/python/typeshed/pull/2628
|
||||
zipdir = zipfile.ZipInfo(dir_arcname + '/') # type: ignore
|
||||
zipdir = zipfile.ZipInfo(dir_arcname + '/')
|
||||
zipdir.external_attr = 0x1ED << 16 # 0o755
|
||||
zip.writestr(zipdir, '')
|
||||
for filename in filenames:
|
||||
|
|
|
@ -23,8 +23,8 @@ except ImportError:
|
|||
from pip._vendor import ipaddress # type: ignore
|
||||
except ImportError:
|
||||
import ipaddr as ipaddress # type: ignore
|
||||
ipaddress.ip_address = ipaddress.IPAddress
|
||||
ipaddress.ip_network = ipaddress.IPNetwork
|
||||
ipaddress.ip_address = ipaddress.IPAddress # type: ignore
|
||||
ipaddress.ip_network = ipaddress.IPNetwork # type: ignore
|
||||
|
||||
|
||||
__all__ = [
|
||||
|
|
|
@ -1 +1 @@
|
|||
mypy == 0.620
|
||||
mypy == 0.650
|
||||
|
|
Loading…
Reference in a new issue