From 89ef777c186ce562a73db39d301b7e92528b538f Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 18 Dec 2018 15:10:40 +0530 Subject: [PATCH] Cleanup for issues fixed with mypy upgrade --- src/pip/_internal/download.py | 5 ++--- src/pip/_internal/index.py | 8 ++----- src/pip/_internal/req/req_file.py | 32 +++++++++++----------------- src/pip/_internal/req/req_install.py | 4 +--- 4 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/pip/_internal/download.py b/src/pip/_internal/download.py index fbd820ad1..2bbe1762c 100644 --- a/src/pip/_internal/download.py +++ b/src/pip/_internal/download.py @@ -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) diff --git a/src/pip/_internal/index.py b/src/pip/_internal/index.py index f8bb51e08..1f2723e38 100644 --- a/src/pip/_internal/index.py +++ b/src/pip/_internal/index.py @@ -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): diff --git a/src/pip/_internal/req/req_file.py b/src/pip/_internal/req/req_file.py index fd9b2b45c..e92b7968b 100644 --- a/src/pip/_internal/req/req_file.py +++ b/src/pip/_internal/req/req_file.py @@ -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 diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 1854e5212..c5dd2bd52 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -877,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: