Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/pip/_internal/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
if TYPE_CHECKING:
from hashlib import _Hash

from pip._vendor.requests.models import Request, Response
from pip._vendor.requests.models import PreparedRequest, Request, Response

from pip._internal.metadata import BaseDistribution
from pip._internal.network.download import _FileDownload
Expand Down Expand Up @@ -314,7 +314,7 @@ def __init__(
self,
error_msg: str,
response: Response | None = None,
request: Request | None = None,
request: Request | PreparedRequest | None = None,
) -> None:
"""
Initialize NetworkConnectionError with `request` and `response`
Expand Down
3 changes: 1 addition & 2 deletions src/pip/_internal/locations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pathlib
import sys
import sysconfig
from typing import Any

from pip._internal.models.scheme import SCHEME_KEYS, Scheme
from pip._internal.utils.compat import WINDOWS
Expand Down Expand Up @@ -134,7 +133,7 @@ def _looks_like_red_hat_scheme() -> bool:
from distutils.command.install import install
from distutils.dist import Distribution

cmd: Any = install(Distribution())
cmd: install = install(Distribution())
cmd.finalize_options()
return (
cmd.exec_prefix == f"{os.path.normpath(sys.exec_prefix)}/local"
Expand Down
5 changes: 4 additions & 1 deletion src/pip/_internal/locations/_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import sys
import sysconfig
from typing import Callable

from pip._internal.exceptions import InvalidSchemeCombination, UserInstallationInvalid
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
Expand All @@ -24,7 +25,9 @@

_AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())

_PREFERRED_SCHEME_API = getattr(sysconfig, "get_preferred_scheme", None)
_PREFERRED_SCHEME_API: Callable[[str], str] | None = getattr(
sysconfig, "get_preferred_scheme", None
)


def _should_use_osx_framework_prefix() -> bool:
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/self_outdated_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os.path
import sys
from dataclasses import dataclass
from typing import Any, Callable
from typing import Callable

from pip._vendor.packaging.version import Version
from pip._vendor.packaging.version import parse as parse_version
Expand Down Expand Up @@ -61,7 +61,7 @@ def _convert_date(isodate: str) -> datetime.datetime:

class SelfCheckState:
def __init__(self, cache_dir: str) -> None:
self._state: dict[str, Any] = {}
self._state: dict[str, str] = {}
self._statefile_path = None

# Try to load the existing state
Expand Down
5 changes: 2 additions & 3 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,9 @@ def __str__(self) -> str:
return self.redacted

# This is useful for testing.
def __eq__(self, other: Any) -> bool:
if type(self) is not type(other):
def __eq__(self, other: object) -> bool:
if type(self) is not type(other) or not isinstance(other, HiddenText):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is really about type narrowing, since mypy doesn't do that for type(self) is not type(other). The reason for the change at all comes down to the fact that self.secret == other.secret isn't recognised as a bool when other is Any.

Copy link
Contributor Author

@pelson pelson Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reflecting on this, I probably would rewrite this for clarity as:

    def __eq__(self, other: object) -> bool:
        if type(self) is type(other):
            # The string being used for redaction doesn't also have to match,
            # just the raw, original string.
            return self.secret == cast(HiddenText, other).secret
        return False

return False

# The string being used for redaction doesn't also have to match,
# just the raw, original string.
return self.secret == other.secret
Expand Down