mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 04:54:47 +08:00
Recommend to use mypy error codes if applicable (#6305)
This commit is contained in:
@@ -389,7 +389,9 @@ Some further tips for good type hints:
|
||||
* in Python 2, whenever possible, use `unicode` if that's the only
|
||||
possible type, and `Text` if it can be either `unicode` or `bytes`;
|
||||
* use platform checks like `if sys.platform == 'win32'` to denote
|
||||
platform-dependent APIs.
|
||||
platform-dependent APIs;
|
||||
* use mypy error codes for mypy-specific `# type: ignore` annotations,
|
||||
e.g. `# type: ignore[override]` for Liskov Substitution Principle violations.
|
||||
|
||||
Imports in stubs are considered private (not part of the exported API)
|
||||
unless:
|
||||
|
||||
@@ -419,7 +419,7 @@ class str(Sequence[str]):
|
||||
def maketrans(__x: str, __y: str, __z: str | None = ...) -> dict[int, int | None]: ...
|
||||
def __add__(self, __s: str) -> str: ...
|
||||
# Incompatible with Sequence.__contains__
|
||||
def __contains__(self, __o: str) -> bool: ... # type: ignore
|
||||
def __contains__(self, __o: str) -> bool: ... # type: ignore[override]
|
||||
def __eq__(self, __x: object) -> bool: ...
|
||||
def __ge__(self, __x: str) -> bool: ...
|
||||
def __getitem__(self, __i: int | slice) -> str: ...
|
||||
@@ -528,7 +528,7 @@ class bytes(ByteString):
|
||||
def __rmul__(self, __n: SupportsIndex) -> bytes: ...
|
||||
def __mod__(self, __value: Any) -> bytes: ...
|
||||
# Incompatible with Sequence.__contains__
|
||||
def __contains__(self, __o: SupportsIndex | bytes) -> bool: ... # type: ignore
|
||||
def __contains__(self, __o: SupportsIndex | bytes) -> bool: ... # type: ignore[override]
|
||||
def __eq__(self, __x: object) -> bool: ...
|
||||
def __ne__(self, __x: object) -> bool: ...
|
||||
def __lt__(self, __x: bytes) -> bool: ...
|
||||
@@ -620,7 +620,7 @@ class bytearray(MutableSequence[int], ByteString):
|
||||
def __iter__(self) -> Iterator[int]: ...
|
||||
def __str__(self) -> str: ...
|
||||
def __repr__(self) -> str: ...
|
||||
__hash__: None # type: ignore
|
||||
__hash__: None # type: ignore[assignment]
|
||||
@overload
|
||||
def __getitem__(self, __i: SupportsIndex) -> int: ...
|
||||
@overload
|
||||
@@ -637,7 +637,7 @@ class bytearray(MutableSequence[int], ByteString):
|
||||
def __imul__(self, __n: SupportsIndex) -> bytearray: ...
|
||||
def __mod__(self, __value: Any) -> bytes: ...
|
||||
# Incompatible with Sequence.__contains__
|
||||
def __contains__(self, __o: SupportsIndex | bytes) -> bool: ... # type: ignore
|
||||
def __contains__(self, __o: SupportsIndex | bytes) -> bool: ... # type: ignore[override]
|
||||
def __eq__(self, __x: object) -> bool: ...
|
||||
def __ne__(self, __x: object) -> bool: ...
|
||||
def __lt__(self, __x: bytes) -> bool: ...
|
||||
@@ -728,7 +728,7 @@ class slice(object):
|
||||
def __init__(self, __stop: Any) -> None: ...
|
||||
@overload
|
||||
def __init__(self, __start: Any, __stop: Any, __step: Any = ...) -> None: ...
|
||||
__hash__: None # type: ignore
|
||||
__hash__: None # type: ignore[assignment]
|
||||
def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ...
|
||||
|
||||
class tuple(Sequence[_T_co], Generic[_T_co]):
|
||||
@@ -785,7 +785,7 @@ class list(MutableSequence[_T], Generic[_T]):
|
||||
def __len__(self) -> int: ...
|
||||
def __iter__(self) -> Iterator[_T]: ...
|
||||
def __str__(self) -> str: ...
|
||||
__hash__: None # type: ignore
|
||||
__hash__: None # type: ignore[assignment]
|
||||
@overload
|
||||
def __getitem__(self, __i: SupportsIndex) -> _T: ...
|
||||
@overload
|
||||
@@ -850,12 +850,12 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
|
||||
if sys.version_info >= (3, 8):
|
||||
def __reversed__(self) -> Iterator[_KT]: ...
|
||||
def __str__(self) -> str: ...
|
||||
__hash__: None # type: ignore
|
||||
__hash__: None # type: ignore[assignment]
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
|
||||
def __or__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
|
||||
def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
|
||||
def __ior__(self, __value: Mapping[_KT, _VT]) -> dict[_KT, _VT]: ... # type: ignore
|
||||
def __ior__(self, __value: Mapping[_KT, _VT]) -> dict[_KT, _VT]: ... # type: ignore[misc]
|
||||
|
||||
class set(MutableSet[_T], Generic[_T]):
|
||||
def __init__(self, __iterable: Iterable[_T] = ...) -> None: ...
|
||||
@@ -892,7 +892,7 @@ class set(MutableSet[_T], Generic[_T]):
|
||||
def __lt__(self, __s: AbstractSet[object]) -> bool: ...
|
||||
def __ge__(self, __s: AbstractSet[object]) -> bool: ...
|
||||
def __gt__(self, __s: AbstractSet[object]) -> bool: ...
|
||||
__hash__: None # type: ignore
|
||||
__hash__: None # type: ignore[assignment]
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
|
||||
|
||||
@@ -938,7 +938,7 @@ class range(Sequence[int]):
|
||||
@overload
|
||||
def __init__(self, __start: SupportsIndex, __stop: SupportsIndex, __step: SupportsIndex = ...) -> None: ...
|
||||
def count(self, __value: int) -> int: ...
|
||||
def index(self, __value: int) -> int: ... # type: ignore
|
||||
def index(self, __value: int) -> int: ... # type: ignore[override]
|
||||
def __len__(self) -> int: ...
|
||||
def __contains__(self, __o: object) -> bool: ...
|
||||
def __iter__(self) -> Iterator[int]: ...
|
||||
@@ -968,10 +968,10 @@ class property(object):
|
||||
def __delete__(self, __obj: Any) -> None: ...
|
||||
|
||||
@final
|
||||
class _NotImplementedType(Any): # type: ignore
|
||||
class _NotImplementedType(Any): # type: ignore[misc]
|
||||
# A little weird, but typing the __call__ as NotImplemented makes the error message
|
||||
# for NotImplemented() much better
|
||||
__call__: NotImplemented # type: ignore
|
||||
__call__: NotImplemented # type: ignore[valid-type]
|
||||
|
||||
NotImplemented: _NotImplementedType
|
||||
|
||||
|
||||
@@ -207,6 +207,7 @@ def get_mypy_flags(args, major: int, minor: int, temp_name: str, *, custom_types
|
||||
"--no-implicit-optional",
|
||||
"--disallow-any-generics",
|
||||
"--warn-incomplete-stub",
|
||||
"--show-error-codes",
|
||||
"--no-error-summary",
|
||||
]
|
||||
if custom_typeshed:
|
||||
|
||||
Reference in New Issue
Block a user