Merge pull request #8271 from deveshks/add-mypy-cache-xmlrpc-form_contr

Add mypy type annotations to cache, xmlrpc in network and format_control in models module
This commit is contained in:
Stéphane Bidoul 2020-05-20 10:19:30 +02:00 committed by GitHub
commit 803a6f2017
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 11 deletions

View File

@ -1,6 +1,3 @@
# The following comment should be removed at some point in the future.
# mypy: strict-optional=False
from pip._vendor.packaging.utils import canonicalize_name from pip._vendor.packaging.utils import canonicalize_name
from pip._internal.exceptions import CommandError from pip._internal.exceptions import CommandError
@ -42,7 +39,7 @@ class FormatControl(object):
@staticmethod @staticmethod
def handle_mutual_excludes(value, target, other): def handle_mutual_excludes(value, target, other):
# type: (str, Optional[Set[str]], Optional[Set[str]]) -> None # type: (str, Set[str], Set[str]) -> None
if value.startswith('-'): if value.startswith('-'):
raise CommandError( raise CommandError(
"--no-binary / --only-binary option requires 1 argument." "--no-binary / --only-binary option requires 1 argument."

View File

@ -1,9 +1,6 @@
"""HTTP cache implementation. """HTTP cache implementation.
""" """
# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False
import os import os
from contextlib import contextmanager from contextlib import contextmanager
@ -16,7 +13,7 @@ from pip._internal.utils.misc import ensure_dir
from pip._internal.utils.typing import MYPY_CHECK_RUNNING from pip._internal.utils.typing import MYPY_CHECK_RUNNING
if MYPY_CHECK_RUNNING: if MYPY_CHECK_RUNNING:
from typing import Optional from typing import Optional, Iterator
def is_from_cache(response): def is_from_cache(response):
@ -26,6 +23,7 @@ def is_from_cache(response):
@contextmanager @contextmanager
def suppressed_cache_errors(): def suppressed_cache_errors():
# type: () -> Iterator[None]
"""If we can't access the cache then we can just skip caching and process """If we can't access the cache then we can just skip caching and process
requests as if caching wasn't enabled. requests as if caching wasn't enabled.
""" """

View File

@ -1,9 +1,6 @@
"""xmlrpclib.Transport implementation """xmlrpclib.Transport implementation
""" """
# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False
import logging import logging
from pip._vendor import requests from pip._vendor import requests
@ -12,6 +9,12 @@ from pip._vendor import requests
from pip._vendor.six.moves import xmlrpc_client # type: ignore from pip._vendor.six.moves import xmlrpc_client # type: ignore
from pip._vendor.six.moves.urllib import parse as urllib_parse from pip._vendor.six.moves.urllib import parse as urllib_parse
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
if MYPY_CHECK_RUNNING:
from typing import Dict
from pip._internal.network.session import PipSession
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -21,12 +24,14 @@ class PipXmlrpcTransport(xmlrpc_client.Transport):
""" """
def __init__(self, index_url, session, use_datetime=False): def __init__(self, index_url, session, use_datetime=False):
# type: (str, PipSession, bool) -> None
xmlrpc_client.Transport.__init__(self, use_datetime) xmlrpc_client.Transport.__init__(self, use_datetime)
index_parts = urllib_parse.urlparse(index_url) index_parts = urllib_parse.urlparse(index_url)
self._scheme = index_parts.scheme self._scheme = index_parts.scheme
self._session = session self._session = session
def request(self, host, handler, request_body, verbose=False): def request(self, host, handler, request_body, verbose=False):
# type: (str, str, Dict[str, str], bool) -> None
parts = (self._scheme, host, handler, None, None, None) parts = (self._scheme, host, handler, None, None, None)
url = urllib_parse.urlunparse(parts) url = urllib_parse.urlunparse(parts)
try: try: