1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

remove disallow_untyped_defs=False for more modules

This commit is contained in:
Maxim Kurnikov 2019-12-13 10:22:21 +03:00
parent 58e2a99ccf
commit 3cb30385d8
8 changed files with 24 additions and 23 deletions

View file

@ -2,7 +2,6 @@
# The following comment should be removed at some point in the future.
# mypy: strict-optional=False
# mypy: disallow-untyped-defs=False
from __future__ import absolute_import
@ -904,6 +903,7 @@ class PackageFinder(object):
installed_version = parse_version(req.satisfied_by.version)
def _format_versions(cand_iter):
# type: (Iterable[InstallationCandidate]) -> str
# This repeated parse_version and str() conversion is needed to
# handle different vendoring sources from pip and pkg_resources.
# If we stop using the pkg_resources provided specifier and start

View file

@ -1,8 +1,5 @@
"""Primary application entrypoint.
"""
# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False
from __future__ import absolute_import
import locale
@ -15,6 +12,10 @@ from pip._internal.cli.main_parser import parse_command
from pip._internal.commands import create_command
from pip._internal.exceptions import PipError
from pip._internal.utils import deprecation
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
if MYPY_CHECK_RUNNING:
from typing import List, Optional
logger = logging.getLogger(__name__)
@ -46,6 +47,7 @@ logger = logging.getLogger(__name__)
# main, this should not be an issue in practice.
def main(args=None):
# type: (Optional[List[str]]) -> int
if args is None:
args = sys.argv[1:]

View file

@ -1,6 +1,3 @@
# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False
from pip._vendor.packaging.version import parse as parse_version
from pip._internal.utils.models import KeyBasedCompareMixin
@ -33,6 +30,7 @@ class InstallationCandidate(KeyBasedCompareMixin):
)
def __str__(self):
# type: () -> str
return '{!r} candidate (version {} at {})'.format(
self.name, self.version, self.link,
)

View file

@ -1,6 +1,3 @@
# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False
import os
import posixpath
import re
@ -67,6 +64,7 @@ class Link(KeyBasedCompareMixin):
super(Link, self).__init__(key=url, defining_class=Link)
def __str__(self):
# type: () -> str
if self.requires_python:
rp = ' (requires-python:%s)' % self.requires_python
else:
@ -78,6 +76,7 @@ class Link(KeyBasedCompareMixin):
return redact_auth_from_url(str(self._url))
def __repr__(self):
# type: () -> str
return '<Link %s>' % self
@property
@ -211,6 +210,7 @@ class Link(KeyBasedCompareMixin):
@property
def has_hash(self):
# type: () -> bool
return self.hash_name is not None
def is_hash_allowed(self, hashes):

View file

@ -1,6 +1,3 @@
# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False
import itertools
import logging
import os
@ -101,6 +98,7 @@ class SearchScope(object):
"""
def mkurl_pypi_url(url):
# type: (str) -> str
loc = posixpath.join(
url,
urllib_parse.quote(canonicalize_name(project_name)))

View file

@ -1,6 +1,3 @@
# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False
from __future__ import absolute_import
import hashlib
@ -59,6 +56,7 @@ class Hashes(object):
hash_name, # type: str
hex_digest, # type: str
):
# type: (...) -> bool
"""Return whether the given hex digest is allowed."""
return hex_digest in self._allowed.get(hash_name, [])

View file

@ -1,6 +1,3 @@
# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False
import os.path
DELETE_MARKER_MESSAGE = '''\
@ -14,6 +11,7 @@ PIP_DELETE_MARKER_FILENAME = 'pip-delete-this-directory.txt'
def has_delete_marker_file(directory):
# type: (str) -> bool
return os.path.exists(os.path.join(directory, PIP_DELETE_MARKER_FILENAME))

View file

@ -1,6 +1,3 @@
# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False
from __future__ import absolute_import
import errno
@ -16,7 +13,9 @@ from pip._internal.utils.misc import rmtree
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
if MYPY_CHECK_RUNNING:
from typing import Iterator, Optional
from typing import Any, Iterator, Optional, TypeVar
_T = TypeVar('_T', bound='TempDirectory')
logger = logging.getLogger(__name__)
@ -93,16 +92,20 @@ class TempDirectory(object):
return self._path
def __repr__(self):
# type: () -> str
return "<{} {!r}>".format(self.__class__.__name__, self.path)
def __enter__(self):
# type: (_T) -> _T
return self
def __exit__(self, exc, value, tb):
# type: (Any, Any, Any) -> None
if self.delete:
self.cleanup()
def _create(self, kind):
# type: (str) -> str
"""Create a temporary directory and store its path in self.path
"""
# We realpath here because some systems have their default tmpdir
@ -116,6 +119,7 @@ class TempDirectory(object):
return path
def cleanup(self):
# type: () -> None
"""Remove the temporary directory created and reset state
"""
self._deleted = True
@ -145,11 +149,13 @@ class AdjacentTempDirectory(TempDirectory):
LEADING_CHARS = "-~.=%0123456789"
def __init__(self, original, delete=None):
# type: (str, Optional[bool]) -> None
self.original = original.rstrip('/\\')
super(AdjacentTempDirectory, self).__init__(delete=delete)
@classmethod
def _generate_names(cls, name):
# type: (str) -> Iterator[str]
"""Generates a series of temporary names.
The algorithm replaces the leading characters in the name
@ -173,6 +179,7 @@ class AdjacentTempDirectory(TempDirectory):
yield new_name
def _create(self, kind):
# type: (str) -> str
root, name = os.path.split(self.original)
for candidate in self._generate_names(name):
path = os.path.join(root, candidate)