Skip to content

Commit

Permalink
refactor: use typing_extensions.Self (#9251)
Browse files Browse the repository at this point in the history
  • Loading branch information
bswck authored Sep 16, 2024
1 parent 65b611a commit 36fedb5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
12 changes: 3 additions & 9 deletions src/poetry/inspection/lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from typing import Any
from typing import BinaryIO
from typing import ClassVar
from typing import TypeVar
from typing import cast
from urllib.parse import urlparse
from zipfile import BadZipFile
Expand All @@ -34,6 +33,7 @@

from packaging.metadata import RawMetadata
from requests import Session
from typing_extensions import Self

from poetry.utils.authenticator import Authenticator

Expand Down Expand Up @@ -168,9 +168,6 @@ def minimal_intervals_covering(
yield from self._merge(start, end, left, right)


T = TypeVar("T", bound="ReadOnlyIOWrapper")


class ReadOnlyIOWrapper(BinaryIO):
"""Implement read-side ``BinaryIO`` methods wrapping an inner ``BinaryIO``.
Expand All @@ -181,7 +178,7 @@ class ReadOnlyIOWrapper(BinaryIO):
def __init__(self, inner: BinaryIO) -> None:
self._file = inner

def __enter__(self: T) -> T:
def __enter__(self) -> Self:
self._file.__enter__()
return self

Expand Down Expand Up @@ -286,9 +283,6 @@ def writelines(self, lines: Iterable[Any]) -> None:
raise NotImplementedError


U = TypeVar("U", bound="LazyFileOverHTTP")


class LazyFileOverHTTP(ReadOnlyIOWrapper):
"""File-like object representing a fixed-length file over HTTP.
Expand All @@ -311,7 +305,7 @@ def __init__(
self._session = session
self._url = url

def __enter__(self: U) -> U:
def __enter__(self) -> Self:
super().__enter__()
self._setup_content()
return self
Expand Down
6 changes: 2 additions & 4 deletions src/poetry/installation/operations/operation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TypeVar


if TYPE_CHECKING:
from poetry.core.packages.package import Package

T = TypeVar("T", bound="Operation")
from typing_extensions import Self


class Operation:
Expand Down Expand Up @@ -46,7 +44,7 @@ def format_version(self, package: Package) -> str:
version: str = package.full_pretty_version
return version

def skip(self: T, reason: str) -> T:
def skip(self, reason: str) -> Self:
self._skipped = True
self._skip_reason = reason

Expand Down
6 changes: 2 additions & 4 deletions src/poetry/puzzle/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import TYPE_CHECKING
from typing import FrozenSet
from typing import Tuple
from typing import TypeVar

from poetry.mixology import resolve_version
from poetry.mixology.failure import SolveFailure
Expand All @@ -27,6 +26,7 @@
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package
from poetry.core.packages.project_package import ProjectPackage
from typing_extensions import Self

from poetry.puzzle.transaction import Transaction
from poetry.repositories import RepositoryPool
Expand Down Expand Up @@ -199,16 +199,14 @@ def _solve(self) -> tuple[list[Package], list[int]]:

DFSNodeID = Tuple[str, FrozenSet[str], bool]

T = TypeVar("T", bound="DFSNode")


class DFSNode:
def __init__(self, id: DFSNodeID, name: str, base_name: str) -> None:
self.id = id
self.name = name
self.base_name = base_name

def reachable(self: T) -> Sequence[T]:
def reachable(self) -> Sequence[Self]:
return []

def visit(self, parents: list[PackageNode]) -> None:
Expand Down

0 comments on commit 36fedb5

Please sign in to comment.