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

Add mypy type annotations to cache, xmlrpc in network and format_control in models module #8271

Merged
merged 5 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Empty file.
5 changes: 1 addition & 4 deletions src/pip/_internal/models/format_control.py
Original file line number Diff line number Diff line change
@@ -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._internal.exceptions import CommandError
Expand Down Expand Up @@ -42,7 +39,7 @@ def __repr__(self):

@staticmethod
def handle_mutual_excludes(value, target, other):
# type: (str, Optional[Set[str]], Optional[Set[str]]) -> None
# type: (str, Set[str], Set[str]) -> None
deveshks marked this conversation as resolved.
Show resolved Hide resolved
if value.startswith('-'):
raise CommandError(
"--no-binary / --only-binary option requires 1 argument."
Expand Down
6 changes: 2 additions & 4 deletions src/pip/_internal/network/cache.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""HTTP cache implementation.
"""

# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False

import os
from contextlib import contextmanager

Expand All @@ -16,7 +13,7 @@
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import Optional
from typing import Optional, Iterator


def is_from_cache(response):
Expand All @@ -26,6 +23,7 @@ def is_from_cache(response):

@contextmanager
def suppressed_cache_errors():
# type: () -> Iterator[None]
"""If we can't access the cache then we can just skip caching and process
requests as if caching wasn't enabled.
"""
Expand Down
11 changes: 8 additions & 3 deletions src/pip/_internal/network/xmlrpc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""xmlrpclib.Transport implementation
"""

# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False

import logging

from pip._vendor import requests
Expand All @@ -12,6 +9,12 @@
from pip._vendor.six.moves import xmlrpc_client # type: ignore
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__)


Expand All @@ -21,12 +24,14 @@ class PipXmlrpcTransport(xmlrpc_client.Transport):
"""

def __init__(self, index_url, session, use_datetime=False):
# type: (str, PipSession, bool) -> None
xmlrpc_client.Transport.__init__(self, use_datetime)
index_parts = urllib_parse.urlparse(index_url)
self._scheme = index_parts.scheme
self._session = session

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)
url = urllib_parse.urlunparse(parts)
try:
Expand Down