From ff6b13a8b85e21f8ac0001a78877ab1d605554a2 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 14 Jun 2021 07:53:14 -0500 Subject: [PATCH 01/16] Complete the annotations in `pip/_internal/cli` This is the second part of my job made on #10018, where I must complete all the annotations from `pip/_internal/cli`. --- src/pip/_internal/cli/progress_bars.py | 32 +++++++++----------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/pip/_internal/cli/progress_bars.py b/src/pip/_internal/cli/progress_bars.py index 3064c85697b..87817980bc0 100644 --- a/src/pip/_internal/cli/progress_bars.py +++ b/src/pip/_internal/cli/progress_bars.py @@ -18,8 +18,7 @@ colorama = None -def _select_progress_class(preferred, fallback): - # type: (Bar, Bar) -> Bar +def _select_progress_class(preferred: Bar, fallback: Bar) -> Bar: encoding = getattr(preferred.file, "encoding", None) # If we don't know what encoding this file is in, then we'll just assume @@ -67,8 +66,7 @@ class InterruptibleMixin: download has already completed, for example. """ - def __init__(self, *args, **kwargs): - # type: (List[Any], Dict[Any, Any]) -> None + def __init__(self, *args: List[Any], **kwargs: Dict[Any, Any]) -> None: """ Save the original SIGINT handler for later. """ @@ -85,8 +83,7 @@ def __init__(self, *args, **kwargs): if self.original_handler is None: self.original_handler = default_int_handler - def finish(self): - # type: () -> None + def finish(self) -> None: """ Restore the original SIGINT handler after finishing. @@ -108,8 +105,7 @@ def handle_sigint(self, signum, frame): # type: ignore class SilentBar(Bar): - def update(self): - # type: () -> None + def update(self) -> None: pass @@ -122,28 +118,25 @@ class BlueEmojiBar(IncrementalBar): class DownloadProgressMixin: - def __init__(self, *args, **kwargs): + def __init__(self, *args: List[Any], **kwargs: Dict[Any, Any]) -> None: # type: (List[Any], Dict[Any, Any]) -> None # https://github.com/python/mypy/issues/5887 super().__init__(*args, **kwargs) # type: ignore self.message = (" " * (get_indentation() + 2)) + self.message # type: str @property - def downloaded(self): - # type: () -> str + def downloaded(self) -> str: return format_size(self.index) # type: ignore @property - def download_speed(self): - # type: () -> str + def download_speed(self) -> str: # Avoid zero division errors... if self.avg == 0.0: # type: ignore return "..." return format_size(1 / self.avg) + "/s" # type: ignore @property - def pretty_eta(self): - # type: () -> str + def pretty_eta(self) -> str: if self.eta: # type: ignore return f"eta {self.eta_td}" # type: ignore return "" @@ -158,8 +151,7 @@ def iter(self, it): # type: ignore class WindowsMixin: - def __init__(self, *args, **kwargs): - # type: (List[Any], Dict[Any, Any]) -> None + def __init__(self, *args: List[Any], **kwargs: Dict[Any, Any]) -> None: # The Windows terminal does not support the hide/show cursor ANSI codes # even with colorama. So we'll ensure that hide_cursor is False on # Windows. @@ -221,14 +213,12 @@ class DownloadProgressSpinner( file = sys.stdout suffix = "%(downloaded)s %(download_speed)s" - def next_phase(self): - # type: () -> str + def next_phase(self) -> str: if not hasattr(self, "_phaser"): self._phaser = itertools.cycle(self.phases) return next(self._phaser) - def update(self): - # type: () -> None + def update(self) -> None: message = self.message % self phase = self.next_phase() suffix = self.suffix % self From ec81b0918b1cbd881b0107118bdbd253b5be3a31 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 14 Jun 2021 07:57:52 -0500 Subject: [PATCH 02/16] Create 10065.trivial.rst This is the news file for my pull request. --- news/10065.trivial.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/10065.trivial.rst diff --git a/news/10065.trivial.rst b/news/10065.trivial.rst new file mode 100644 index 00000000000..d6bbe71c21a --- /dev/null +++ b/news/10065.trivial.rst @@ -0,0 +1 @@ +Fixed all the annotations from ``pip/_internal/cli``. From 7a79567917bb42f624947b71b0aafe679a62c612 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 14 Jun 2021 08:04:30 -0500 Subject: [PATCH 03/16] Update the annotations in `progress_bars.py` I just changed one function annotations, on line 121. --- src/pip/_internal/cli/progress_bars.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pip/_internal/cli/progress_bars.py b/src/pip/_internal/cli/progress_bars.py index 87817980bc0..716850a0785 100644 --- a/src/pip/_internal/cli/progress_bars.py +++ b/src/pip/_internal/cli/progress_bars.py @@ -119,7 +119,6 @@ class BlueEmojiBar(IncrementalBar): class DownloadProgressMixin: def __init__(self, *args: List[Any], **kwargs: Dict[Any, Any]) -> None: - # type: (List[Any], Dict[Any, Any]) -> None # https://github.com/python/mypy/issues/5887 super().__init__(*args, **kwargs) # type: ignore self.message = (" " * (get_indentation() + 2)) + self.message # type: str From 0a5e30f5f7b92e2c617b20961765012cb0960ba5 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 14 Jun 2021 08:22:12 -0500 Subject: [PATCH 04/16] Update the annotations in req_command.py --- src/pip/_internal/cli/req_command.py | 102 ++++++++++++--------------- 1 file changed, 44 insertions(+), 58 deletions(-) diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index 7ed623880ac..f95a1529649 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -50,14 +50,12 @@ class SessionCommandMixin(CommandContextMixIn): A class mixin for command classes needing _build_session(). """ - def __init__(self): - # type: () -> None + def __init__(self) -> None: super().__init__() self._session = None # Optional[PipSession] @classmethod - def _get_index_urls(cls, options): - # type: (Values) -> Optional[List[str]] + def _get_index_urls(cls, options: Values) -> Optional[List[str]]: """Return a list of index urls from user-provided options.""" index_urls = [] if not getattr(options, "no_index", False): @@ -70,8 +68,7 @@ def _get_index_urls(cls, options): # Return None rather than an empty list return index_urls or None - def get_default_session(self, options): - # type: (Values) -> PipSession + def get_default_session(self, options: Values) -> PipSession: """Get a default-managed session.""" if self._session is None: self._session = self.enter_context(self._build_session(options)) @@ -81,8 +78,9 @@ def get_default_session(self, options): assert self._session is not None return self._session - def _build_session(self, options, retries=None, timeout=None): - # type: (Values, Optional[int], Optional[int]) -> PipSession + def _build_session( + self, options: Values, retries: Optional[int]=None, timeout: Optional[int]=None + ) -> PipSession: assert not options.cache_dir or os.path.isabs(options.cache_dir) session = PipSession( cache=( @@ -126,8 +124,7 @@ class IndexGroupCommand(Command, SessionCommandMixin): This also corresponds to the commands that permit the pip version check. """ - def handle_pip_version_check(self, options): - # type: (Values) -> None + def handle_pip_version_check(self, options: Values) -> None: """ Do the pip version check if not disabled. @@ -154,8 +151,7 @@ def handle_pip_version_check(self, options): ] -def warn_if_run_as_root(): - # type: () -> None +def warn_if_run_as_root() -> None: """Output a warning for sudo users on Unix. In a virtual environment, sudo pip still writes to virtualenv. @@ -184,19 +180,16 @@ def warn_if_run_as_root(): ) -def with_cleanup(func): - # type: (Any) -> Any +def with_cleanup(func: Any) -> Any: """Decorator for common logic related to managing temporary directories. """ - def configure_tempdir_registry(registry): - # type: (TempDirectoryTypeRegistry) -> None + def configure_tempdir_registry(registry: TempDirectoryTypeRegistry) -> None: for t in KEEPABLE_TEMPDIR_TYPES: registry.set_delete(t, False) - def wrapper(self, options, args): - # type: (RequirementCommand, Values, List[Any]) -> Optional[int] + def wrapper(self: RequirementCommand, options: Values, args: List[Any]) -> Optional[int]: assert self.tempdir_registry is not None if options.no_clean: configure_tempdir_registry(self.tempdir_registry) @@ -214,15 +207,13 @@ def wrapper(self, options, args): class RequirementCommand(IndexGroupCommand): - def __init__(self, *args, **kw): - # type: (Any, Any) -> None + def __init__(self, *args: Any, **kw: Any) -> None: super().__init__(*args, **kw) self.cmd_opts.add_option(cmdoptions.no_clean()) @staticmethod - def determine_resolver_variant(options): - # type: (Values) -> str + def determine_resolver_variant(options: Values) -> str: """Determines which resolver should be used, based on the given options.""" if "legacy-resolver" in options.deprecated_features_enabled: return "legacy" @@ -232,15 +223,14 @@ def determine_resolver_variant(options): @classmethod def make_requirement_preparer( cls, - temp_build_dir, # type: TempDirectory - options, # type: Values - req_tracker, # type: RequirementTracker - session, # type: PipSession - finder, # type: PackageFinder - use_user_site, # type: bool - download_dir=None, # type: str - ): - # type: (...) -> RequirementPreparer + temp_build_dir: TempDirectory, + options: Values, + req_tracker: RequirementTracker, + session: PipSession, + finder: PackageFinder, + use_user_site: bool, + download_dir: str=None, + ) -> RequirementParser: """ Create a RequirementPreparer instance for the given parameters. """ @@ -283,19 +273,18 @@ def make_requirement_preparer( @classmethod def make_resolver( cls, - preparer, # type: RequirementPreparer - finder, # type: PackageFinder - options, # type: Values - wheel_cache=None, # type: Optional[WheelCache] - use_user_site=False, # type: bool - ignore_installed=True, # type: bool - ignore_requires_python=False, # type: bool - force_reinstall=False, # type: bool - upgrade_strategy="to-satisfy-only", # type: str - use_pep517=None, # type: Optional[bool] - py_version_info=None, # type: Optional[Tuple[int, ...]] - ): - # type: (...) -> BaseResolver + preparer: RequirementPreparer, + finder: PackageFinder, + options: Values, + wheel_cache: Optional[WheelCache]=None, + use_user_site: bool=False, + ignore_installed: bool=True, + ignore_requires_python: bool=False, + force_reinstall: bool=False, + upgrade_strategy: str="to-satisfy-only", + use_pep517: Optional[bool]=None, + py_version_info: Optional[Tuple[int, ...]]=None, + ) -> BaseResolver: """ Create a Resolver instance for the given parameters. """ @@ -342,12 +331,11 @@ def make_resolver( def get_requirements( self, - args, # type: List[str] - options, # type: Values - finder, # type: PackageFinder - session, # type: PipSession - ): - # type: (...) -> List[InstallRequirement] + args: List[str], + options: Values, + finder: PackageFinder, + session: PipSession, + ) -> List[InstallRequirement]: """ Parse command-line arguments into the corresponding requirements. """ @@ -421,8 +409,7 @@ def get_requirements( return requirements @staticmethod - def trace_basic_info(finder): - # type: (PackageFinder) -> None + def trace_basic_info(finder: PackageFinder) -> None: """ Trace basic information about the provided objects. """ @@ -434,12 +421,11 @@ def trace_basic_info(finder): def _build_package_finder( self, - options, # type: Values - session, # type: PipSession - target_python=None, # type: Optional[TargetPython] - ignore_requires_python=None, # type: Optional[bool] - ): - # type: (...) -> PackageFinder + options: Values, + session: PipSession, + target_python: Optional[TargetPython]=None, + ignore_requires_python: Optional[bool]=None, + ) -> PackageFinder: """ Create a package finder appropriate to this requirement command. From f0038637ea18a49e793705b059d9e2f533a4907f Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 14 Jun 2021 08:29:19 -0500 Subject: [PATCH 05/16] Update req_command.py Just update the annotations according to the CI last failure. --- src/pip/_internal/cli/req_command.py | 31 ++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index f95a1529649..015f772f7c9 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -79,7 +79,10 @@ def get_default_session(self, options: Values) -> PipSession: return self._session def _build_session( - self, options: Values, retries: Optional[int]=None, timeout: Optional[int]=None + self, + options: Values, + retries: Optional[int] = None, + timeout: Optional[int] = None ) -> PipSession: assert not options.cache_dir or os.path.isabs(options.cache_dir) session = PipSession( @@ -189,7 +192,9 @@ def configure_tempdir_registry(registry: TempDirectoryTypeRegistry) -> None: for t in KEEPABLE_TEMPDIR_TYPES: registry.set_delete(t, False) - def wrapper(self: RequirementCommand, options: Values, args: List[Any]) -> Optional[int]: + def wrapper( + self: RequirementCommand, options: Values, args: List[Any] + ) -> Optional[int]: assert self.tempdir_registry is not None if options.no_clean: configure_tempdir_registry(self.tempdir_registry) @@ -229,7 +234,7 @@ def make_requirement_preparer( session: PipSession, finder: PackageFinder, use_user_site: bool, - download_dir: str=None, + download_dir: str = None, ) -> RequirementParser: """ Create a RequirementPreparer instance for the given parameters. @@ -276,14 +281,14 @@ def make_resolver( preparer: RequirementPreparer, finder: PackageFinder, options: Values, - wheel_cache: Optional[WheelCache]=None, - use_user_site: bool=False, - ignore_installed: bool=True, - ignore_requires_python: bool=False, - force_reinstall: bool=False, - upgrade_strategy: str="to-satisfy-only", - use_pep517: Optional[bool]=None, - py_version_info: Optional[Tuple[int, ...]]=None, + wheel_cache: Optional[WheelCache] = None, + use_user_site: bool = False, + ignore_installed: bool = True, + ignore_requires_python: bool = False, + force_reinstall: bool = False, + upgrade_strategy: str = "to-satisfy-only", + use_pep517: Optional[bool] = None, + py_version_info: Optional[Tuple[int, ...]] = None, ) -> BaseResolver: """ Create a Resolver instance for the given parameters. @@ -423,8 +428,8 @@ def _build_package_finder( self, options: Values, session: PipSession, - target_python: Optional[TargetPython]=None, - ignore_requires_python: Optional[bool]=None, + target_python: Optional[TargetPython] = None, + ignore_requires_python: Optional[bool] = None, ) -> PackageFinder: """ Create a package finder appropriate to this requirement command. From 19a6e96b982b03c60f996dfd9ea95e777dadb6a2 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Mon, 14 Jun 2021 08:31:51 -0500 Subject: [PATCH 06/16] Fix an annotation mistake I wanted to use "RequirementPreparer", not "RequirementParser". --- src/pip/_internal/cli/req_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index 015f772f7c9..fae14dade05 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -235,7 +235,7 @@ def make_requirement_preparer( finder: PackageFinder, use_user_site: bool, download_dir: str = None, - ) -> RequirementParser: + ) -> RequirementPreparer: """ Create a RequirementPreparer instance for the given parameters. """ From 37f3ff1d3e9ecf11eddd72680711ecd8171d0422 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 15 Jun 2021 08:21:47 -0500 Subject: [PATCH 07/16] Fix the annotation structure There were some previous errors with this, but now I fixed them. --- src/pip/_internal/cli/req_command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index fae14dade05..3b5f5aa87ef 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -82,7 +82,7 @@ def _build_session( self, options: Values, retries: Optional[int] = None, - timeout: Optional[int] = None + timeout: Optional[int] = None, ) -> PipSession: assert not options.cache_dir or os.path.isabs(options.cache_dir) session = PipSession( @@ -235,7 +235,7 @@ def make_requirement_preparer( finder: PackageFinder, use_user_site: bool, download_dir: str = None, - ) -> RequirementPreparer: + ) -> RequirementPreparer: """ Create a RequirementPreparer instance for the given parameters. """ From 7b68bd0ba92f7292cb20aebc3ceb02f84ebc1aee Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 15 Jun 2021 08:27:35 -0500 Subject: [PATCH 08/16] Remove a trailing whitespace It is not exactly a problem, it's just to pass the CI. --- src/pip/_internal/cli/req_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index 3b5f5aa87ef..f8111091540 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -81,7 +81,7 @@ def get_default_session(self, options: Values) -> PipSession: def _build_session( self, options: Values, - retries: Optional[int] = None, + retries: Optional[int] = None, timeout: Optional[int] = None, ) -> PipSession: assert not options.cache_dir or os.path.isabs(options.cache_dir) From 72881b4c9886a70edb763d40da1dae99c9e2ab20 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 15 Jun 2021 08:33:27 -0500 Subject: [PATCH 09/16] Remove the whitespaces They fail on the CI checks. --- src/pip/_internal/cli/req_command.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index f8111091540..5a28d495d05 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -79,8 +79,8 @@ def get_default_session(self, options: Values) -> PipSession: return self._session def _build_session( - self, - options: Values, + self, + options: Values, retries: Optional[int] = None, timeout: Optional[int] = None, ) -> PipSession: From 0a2b24fe69f7ab652fc743740f9eda4745f960e4 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Tue, 15 Jun 2021 08:46:35 -0500 Subject: [PATCH 10/16] Update the spinners.py annotations Convert type commentaries into annotations. --- src/pip/_internal/cli/spinners.py | 51 +++++++++++-------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/src/pip/_internal/cli/spinners.py b/src/pip/_internal/cli/spinners.py index 08e156617c4..092c5f9292e 100644 --- a/src/pip/_internal/cli/spinners.py +++ b/src/pip/_internal/cli/spinners.py @@ -14,25 +14,22 @@ class SpinnerInterface: - def spin(self): - # type: () -> None + def spin(self) -> None: raise NotImplementedError() - def finish(self, final_status): - # type: (str) -> None + def finish(self, final_status: str) -> None: raise NotImplementedError() class InteractiveSpinner(SpinnerInterface): def __init__( self, - message, - file=None, - spin_chars="-\\|/", + message: str, + file: IO[str] = None, + spin_chars: str = "-\\|/", # Empirically, 8 updates/second looks nice - min_update_interval_seconds=0.125, + min_update_interval_seconds: float = 0.125, ): - # type: (str, IO[str], str, float) -> None self._message = message if file is None: file = sys.stdout @@ -45,8 +42,7 @@ def __init__( self._file.write(" " * get_indentation() + self._message + " ... ") self._width = 0 - def _write(self, status): - # type: (str) -> None + def _write(self, status: str) -> None: assert not self._finished # Erase what we wrote before by backspacing to the beginning, writing # spaces to overwrite the old text, and then backspacing again @@ -58,16 +54,14 @@ def _write(self, status): self._file.flush() self._rate_limiter.reset() - def spin(self): - # type: () -> None + def spin(self) -> None: if self._finished: return if not self._rate_limiter.ready(): return self._write(next(self._spin_cycle)) - def finish(self, final_status): - # type: (str) -> None + def finish(self, final_status: str) -> None: if self._finished: return self._write(final_status) @@ -81,29 +75,25 @@ def finish(self, final_status): # act as a keep-alive for systems like Travis-CI that take lack-of-output as # an indication that a task has frozen. class NonInteractiveSpinner(SpinnerInterface): - def __init__(self, message, min_update_interval_seconds=60): - # type: (str, float) -> None + def __init__(self, message: str, min_update_interval_seconds: float = 60) -> None: self._message = message self._finished = False self._rate_limiter = RateLimiter(min_update_interval_seconds) self._update("started") - def _update(self, status): - # type: (str) -> None + def _update(self, status: str) -> None: assert not self._finished self._rate_limiter.reset() logger.info("%s: %s", self._message, status) - def spin(self): - # type: () -> None + def spin(self) -> None: if self._finished: return if not self._rate_limiter.ready(): return self._update("still running...") - def finish(self, final_status): - # type: (str) -> None + def finish(self, final_status: str) -> None: if self._finished: return self._update(f"finished with status '{final_status}'") @@ -111,25 +101,21 @@ def finish(self, final_status): class RateLimiter: - def __init__(self, min_update_interval_seconds): - # type: (float) -> None + def __init__(self, min_update_interval_seconds: float) -> None: self._min_update_interval_seconds = min_update_interval_seconds self._last_update = 0 # type: float - def ready(self): - # type: () -> bool + def ready(self) -> bool: now = time.time() delta = now - self._last_update return delta >= self._min_update_interval_seconds - def reset(self): - # type: () -> None + def reset(self) -> None: self._last_update = time.time() @contextlib.contextmanager -def open_spinner(message): - # type: (str) -> Iterator[SpinnerInterface] +def open_spinner(message: str) -> Iterator[SpinnerInterface]: # Interactive spinner goes directly to sys.stdout rather than being routed # through the logging system, but it acts like it has level INFO, # i.e. it's only displayed if we're at level INFO or better. @@ -153,8 +139,7 @@ def open_spinner(message): @contextlib.contextmanager -def hidden_cursor(file): - # type: (IO[str]) -> Iterator[None] +def hidden_cursor(file: IO[str]) -> Iterator[None]: # The Windows terminal does not support the hide/show cursor ANSI codes, # even via colorama. So don't even try. if WINDOWS: From 9d2ee1f8468bba412b5d4e1802225bfcb0aac021 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Wed, 16 Jun 2021 07:49:49 -0500 Subject: [PATCH 11/16] Update src/pip/_internal/cli/progress_bars.py Fix also the original annotation instead of just copying it. Co-authored-by: Tzu-ping Chung --- src/pip/_internal/cli/progress_bars.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/cli/progress_bars.py b/src/pip/_internal/cli/progress_bars.py index 716850a0785..fcdf72d0aab 100644 --- a/src/pip/_internal/cli/progress_bars.py +++ b/src/pip/_internal/cli/progress_bars.py @@ -66,7 +66,7 @@ class InterruptibleMixin: download has already completed, for example. """ - def __init__(self, *args: List[Any], **kwargs: Dict[Any, Any]) -> None: + def __init__(self, *args: Any, **kwargs: Any) -> None: """ Save the original SIGINT handler for later. """ From 411f49fa594fae0ef9e75a621dd326c9a792a33e Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Wed, 16 Jun 2021 07:56:17 -0500 Subject: [PATCH 12/16] Update `pip/_internal/cli/progress_bars.py` Some of the annotations were incorrect. --- src/pip/_internal/cli/progress_bars.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/cli/progress_bars.py b/src/pip/_internal/cli/progress_bars.py index fcdf72d0aab..e344c9b9528 100644 --- a/src/pip/_internal/cli/progress_bars.py +++ b/src/pip/_internal/cli/progress_bars.py @@ -118,7 +118,7 @@ class BlueEmojiBar(IncrementalBar): class DownloadProgressMixin: - def __init__(self, *args: List[Any], **kwargs: Dict[Any, Any]) -> None: + def __init__(self, *args: Any, **kwargs: Any) -> None: # https://github.com/python/mypy/issues/5887 super().__init__(*args, **kwargs) # type: ignore self.message = (" " * (get_indentation() + 2)) + self.message # type: str @@ -150,7 +150,7 @@ def iter(self, it): # type: ignore class WindowsMixin: - def __init__(self, *args: List[Any], **kwargs: Dict[Any, Any]) -> None: + def __init__(self, *args: Any, **kwargs: Any) -> None: # The Windows terminal does not support the hide/show cursor ANSI codes # even with colorama. So we'll ensure that hide_cursor is False on # Windows. From d582d91af28692214743bef3579f8e1055bfa013 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Wed, 16 Jun 2021 07:59:38 -0500 Subject: [PATCH 13/16] Annotate a variable definition It is "self._session: Optional[PipSession] = None" instead of "self._session = None # type: Optional[PipSession]". --- src/pip/_internal/cli/req_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index 5a28d495d05..8f5d3503c9f 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -52,7 +52,7 @@ class SessionCommandMixin(CommandContextMixIn): def __init__(self) -> None: super().__init__() - self._session = None # Optional[PipSession] + self._session: Optional[PipSession] = None @classmethod def _get_index_urls(cls, options: Values) -> Optional[List[str]]: From 0bceddbb48e71f8c1252acbd7096563acb873062 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Wed, 16 Jun 2021 08:06:01 -0500 Subject: [PATCH 14/16] Don't import `typing.List` and `typing.Dict` They were imported but unused. --- src/pip/_internal/cli/progress_bars.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/cli/progress_bars.py b/src/pip/_internal/cli/progress_bars.py index e344c9b9528..4d1413af33f 100644 --- a/src/pip/_internal/cli/progress_bars.py +++ b/src/pip/_internal/cli/progress_bars.py @@ -1,7 +1,7 @@ import itertools import sys from signal import SIGINT, default_int_handler, signal -from typing import Any, Dict, List +from typing import Any from pip._vendor.progress.bar import Bar, FillingCirclesBar, IncrementalBar from pip._vendor.progress.spinner import Spinner From 0431a18dd81354f20eacbefba3e14bb309b518f1 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Wed, 16 Jun 2021 08:11:50 -0500 Subject: [PATCH 15/16] Fix the annotations One of them was incorrect. --- src/pip/_internal/cli/req_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index 8f5d3503c9f..377351e20b9 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -234,7 +234,7 @@ def make_requirement_preparer( session: PipSession, finder: PackageFinder, use_user_site: bool, - download_dir: str = None, + download_dir: Optional[str] = None, ) -> RequirementPreparer: """ Create a RequirementPreparer instance for the given parameters. From ced58b5a1d2d664a0c7480c251d973bf42058783 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Wed, 16 Jun 2021 08:13:08 -0500 Subject: [PATCH 16/16] Update src/pip/_internal/cli/spinners.py Co-authored-by: Tzu-ping Chung --- src/pip/_internal/cli/spinners.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/cli/spinners.py b/src/pip/_internal/cli/spinners.py index 092c5f9292e..4d3ae6e2997 100644 --- a/src/pip/_internal/cli/spinners.py +++ b/src/pip/_internal/cli/spinners.py @@ -75,7 +75,7 @@ def finish(self, final_status: str) -> None: # act as a keep-alive for systems like Travis-CI that take lack-of-output as # an indication that a task has frozen. class NonInteractiveSpinner(SpinnerInterface): - def __init__(self, message: str, min_update_interval_seconds: float = 60) -> None: + def __init__(self, message: str, min_update_interval_seconds: float = 60.0) -> None: self._message = message self._finished = False self._rate_limiter = RateLimiter(min_update_interval_seconds)