mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 21:46:42 +08:00
Always use _typeshed.Self, where applicable (#6880)
* Always use `_typeshed.Self`, where applicable * Revert changes to `google-cloud-ndb` (ambiguous) * Remove empty line added by script * Revert changes to `stubs/python-dateutil/dateutil/relativedelta.pyi` * Manually add a few more that the script missed * Improve `filelock` annotation Source code here:79ec7b2826/src/filelock/_api.py (L207)* Improve `opentracing/scope` annotation Source code here:3e1d357a34/opentracing/scope.py (L71)* Improve `redis/client` stub Source code here:15f315a496/redis/client.py (L1217)* Improve `redis/lock` annotation Source code here:15f315a496/redis/lock.py (L155)* Improve `requests/models` annotation Source code here:d718e75383/requests/models.py (L653)
This commit is contained in:
@@ -11,14 +11,12 @@ from _typeshed import (
|
||||
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
|
||||
from os import PathLike, stat_result
|
||||
from types import TracebackType
|
||||
from typing import IO, Any, BinaryIO, Generator, Sequence, TypeVar, overload
|
||||
from typing import IO, Any, BinaryIO, Generator, Sequence, overload
|
||||
from typing_extensions import Literal
|
||||
|
||||
if sys.version_info >= (3, 9):
|
||||
from types import GenericAlias
|
||||
|
||||
_P = TypeVar("_P", bound=PurePath)
|
||||
|
||||
class PurePath(PathLike[str]):
|
||||
parts: tuple[str, ...]
|
||||
drive: str
|
||||
@@ -28,14 +26,14 @@ class PurePath(PathLike[str]):
|
||||
suffix: str
|
||||
suffixes: list[str]
|
||||
stem: str
|
||||
def __new__(cls: type[_P], *args: StrPath) -> _P: ...
|
||||
def __new__(cls: type[Self], *args: StrPath) -> Self: ...
|
||||
def __hash__(self) -> int: ...
|
||||
def __lt__(self, other: PurePath) -> bool: ...
|
||||
def __le__(self, other: PurePath) -> bool: ...
|
||||
def __gt__(self, other: PurePath) -> bool: ...
|
||||
def __ge__(self, other: PurePath) -> bool: ...
|
||||
def __truediv__(self: _P, key: StrPath) -> _P: ...
|
||||
def __rtruediv__(self: _P, key: StrPath) -> _P: ...
|
||||
def __truediv__(self: Self, key: StrPath) -> Self: ...
|
||||
def __rtruediv__(self: Self, key: StrPath) -> Self: ...
|
||||
def __bytes__(self) -> bytes: ...
|
||||
def as_posix(self) -> str: ...
|
||||
def as_uri(self) -> str: ...
|
||||
@@ -44,16 +42,16 @@ class PurePath(PathLike[str]):
|
||||
if sys.version_info >= (3, 9):
|
||||
def is_relative_to(self, *other: StrPath) -> bool: ...
|
||||
def match(self, path_pattern: str) -> bool: ...
|
||||
def relative_to(self: _P, *other: StrPath) -> _P: ...
|
||||
def with_name(self: _P, name: str) -> _P: ...
|
||||
def relative_to(self: Self, *other: StrPath) -> Self: ...
|
||||
def with_name(self: Self, name: str) -> Self: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def with_stem(self: _P, stem: str) -> _P: ...
|
||||
def with_suffix(self: _P, suffix: str) -> _P: ...
|
||||
def joinpath(self: _P, *other: StrPath) -> _P: ...
|
||||
def with_stem(self: Self, stem: str) -> Self: ...
|
||||
def with_suffix(self: Self, suffix: str) -> Self: ...
|
||||
def joinpath(self: Self, *other: StrPath) -> Self: ...
|
||||
@property
|
||||
def parents(self: _P) -> Sequence[_P]: ...
|
||||
def parents(self: Self) -> Sequence[Self]: ...
|
||||
@property
|
||||
def parent(self: _P) -> _P: ...
|
||||
def parent(self: Self) -> Self: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, type: Any) -> GenericAlias: ...
|
||||
|
||||
@@ -61,13 +59,13 @@ class PurePosixPath(PurePath): ...
|
||||
class PureWindowsPath(PurePath): ...
|
||||
|
||||
class Path(PurePath):
|
||||
def __new__(cls: type[_P], *args: StrPath, **kwargs: Any) -> _P: ...
|
||||
def __new__(cls: type[Self], *args: StrPath, **kwargs: Any) -> Self: ...
|
||||
def __enter__(self: Self) -> Self: ...
|
||||
def __exit__(
|
||||
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
|
||||
) -> bool | None: ...
|
||||
@classmethod
|
||||
def cwd(cls: type[_P]) -> _P: ...
|
||||
def cwd(cls: type[Self]) -> Self: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
def stat(self, *, follow_symlinks: bool = ...) -> stat_result: ...
|
||||
def chmod(self, mode: int, *, follow_symlinks: bool = ...) -> None: ...
|
||||
@@ -75,7 +73,7 @@ class Path(PurePath):
|
||||
def stat(self) -> stat_result: ...
|
||||
def chmod(self, mode: int) -> None: ...
|
||||
def exists(self) -> bool: ...
|
||||
def glob(self: _P, pattern: str) -> Generator[_P, None, None]: ...
|
||||
def glob(self: Self, pattern: str) -> Generator[Self, None, None]: ...
|
||||
def group(self) -> str: ...
|
||||
def is_dir(self) -> bool: ...
|
||||
def is_file(self) -> bool: ...
|
||||
@@ -86,7 +84,7 @@ class Path(PurePath):
|
||||
def is_fifo(self) -> bool: ...
|
||||
def is_block_device(self) -> bool: ...
|
||||
def is_char_device(self) -> bool: ...
|
||||
def iterdir(self: _P) -> Generator[_P, None, None]: ...
|
||||
def iterdir(self: Self) -> Generator[Self, None, None]: ...
|
||||
def lchmod(self, mode: int) -> None: ...
|
||||
def lstat(self) -> stat_result: ...
|
||||
def mkdir(self, mode: int = ..., parents: bool = ..., exist_ok: bool = ...) -> None: ...
|
||||
@@ -147,15 +145,15 @@ class Path(PurePath):
|
||||
) -> IO[Any]: ...
|
||||
def owner(self) -> str: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def readlink(self: _P) -> _P: ...
|
||||
def readlink(self: Self) -> Self: ...
|
||||
if sys.version_info >= (3, 8):
|
||||
def rename(self: _P, target: str | PurePath) -> _P: ...
|
||||
def replace(self: _P, target: str | PurePath) -> _P: ...
|
||||
def rename(self: Self, target: str | PurePath) -> Self: ...
|
||||
def replace(self: Self, target: str | PurePath) -> Self: ...
|
||||
else:
|
||||
def rename(self, target: str | PurePath) -> None: ...
|
||||
def replace(self, target: str | PurePath) -> None: ...
|
||||
def resolve(self: _P, strict: bool = ...) -> _P: ...
|
||||
def rglob(self: _P, pattern: str) -> Generator[_P, None, None]: ...
|
||||
def resolve(self: Self, strict: bool = ...) -> Self: ...
|
||||
def rglob(self: Self, pattern: str) -> Generator[Self, None, None]: ...
|
||||
def rmdir(self) -> None: ...
|
||||
def symlink_to(self, target: str | Path, target_is_directory: bool = ...) -> None: ...
|
||||
if sys.version_info >= (3, 10):
|
||||
@@ -166,9 +164,9 @@ class Path(PurePath):
|
||||
else:
|
||||
def unlink(self) -> None: ...
|
||||
@classmethod
|
||||
def home(cls: type[_P]) -> _P: ...
|
||||
def absolute(self: _P) -> _P: ...
|
||||
def expanduser(self: _P) -> _P: ...
|
||||
def home(cls: type[Self]) -> Self: ...
|
||||
def absolute(self: Self) -> Self: ...
|
||||
def expanduser(self: Self) -> Self: ...
|
||||
def read_bytes(self) -> bytes: ...
|
||||
def read_text(self, encoding: str | None = ..., errors: str | None = ...) -> str: ...
|
||||
def samefile(self, other_path: str | bytes | int | Path) -> bool: ...
|
||||
|
||||
Reference in New Issue
Block a user