Skip to content

Commit faae950

Browse files
authored
Use error codes for type ignores (#8280)
Disable reportSelfClsParameterName for pytype as this is out of typeshed's control Closes: #7497
1 parent 6348a58 commit faae950

File tree

17 files changed

+29
-20
lines changed

17 files changed

+29
-20
lines changed

pyrightconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"reportUnboundVariable": "error",
3939
"reportInvalidStubStatement": "error",
4040
"reportInvalidTypeVarUse": "error",
41-
"reportSelfClsParameterName": "error",
4241
"reportUnsupportedDunderAll": "error",
4342
"reportInconsistentConstructor": "error",
4443
"reportTypeCommentUsage": "error",
@@ -52,4 +51,6 @@
5251
// (which is stricter than mypy's; see mypy issue #10143 and #10157)
5352
// would cause many false positives and catch few bugs.
5453
"reportOverlappingOverload": "none",
54+
// The name of the self/cls parameter is out of typeshed's control.
55+
"reportSelfClsParameterName": "none",
5556
}

pyrightconfig.stricter.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
"reportUnboundVariable": "error",
114114
"reportInvalidStubStatement": "error",
115115
"reportInvalidTypeVarUse": "error",
116-
"reportSelfClsParameterName": "error",
117116
"reportUnsupportedDunderAll": "error",
118117
"reportInconsistentConstructor": "error",
119118
"reportTypeCommentUsage": "error",
@@ -127,4 +126,6 @@
127126
// (which is stricter than mypy's; see mypy issue #10143 and #10157)
128127
// would cause many false positives and catch few bugs.
129128
"reportOverlappingOverload": "none",
129+
// The name of the self/cls parameter is out of typeshed's control.
130+
"reportSelfClsParameterName": "none",
130131
}

stdlib/builtins.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class object:
8585
def __class__(self: Self) -> type[Self]: ...
8686
# Ignore errors about type mismatch between property getter and setter
8787
@__class__.setter
88-
def __class__(self, __type: type[object]) -> None: ... # type: ignore # noqa: F811
88+
def __class__(self, __type: type[object]) -> None: ... # noqa: F811
8989
def __init__(self) -> None: ...
9090
def __new__(cls: type[Self]) -> Self: ...
9191
# N.B. `object.__setattr__` and `object.__delattr__` are heavily special-cased by type checkers.

stdlib/ctypes/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class _SimpleCData(Generic[_T], _CData):
192192
value: _T
193193
# The TypeVar can be unsolved here,
194194
# but we can't use overloads without creating many, many mypy false-positive errors
195-
def __init__(self, value: _T = ...) -> None: ... # type: ignore
195+
def __init__(self, value: _T = ...) -> None: ... # pyright: ignore[reportInvalidTypeVarUse]
196196

197197
class c_byte(_SimpleCData[int]): ...
198198

stdlib/enum.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class _EnumDict(dict[str, Any]):
8080
class EnumMeta(ABCMeta):
8181
if sys.version_info >= (3, 11):
8282
def __new__(
83-
metacls: type[Self], # type: ignore
83+
metacls: type[Self],
8484
cls: str,
8585
bases: tuple[type, ...],
8686
classdict: _EnumDict,
@@ -90,9 +90,9 @@ class EnumMeta(ABCMeta):
9090
**kwds: Any,
9191
) -> Self: ...
9292
elif sys.version_info >= (3, 9):
93-
def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, **kwds: Any) -> Self: ... # type: ignore
93+
def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, **kwds: Any) -> Self: ...
9494
else:
95-
def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict) -> Self: ... # type: ignore
95+
def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict) -> Self: ...
9696

9797
if sys.version_info >= (3, 9):
9898
@classmethod

stdlib/importlib/metadata/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class MetadataPathFinder(DistributionFinder):
170170
def find_distributions(cls, context: DistributionFinder.Context = ...) -> Iterable[PathDistribution]: ...
171171
if sys.version_info >= (3, 10):
172172
# Yes, this is an instance method that has argumend named "cls"
173-
def invalidate_caches(cls) -> None: ... # type: ignore
173+
def invalidate_caches(cls) -> None: ...
174174

175175
class PathDistribution(Distribution):
176176
def __init__(self, path: Path) -> None: ...

stdlib/subprocess.pyi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ class CompletedProcess(Generic[_T]):
9191
# and writing all the overloads would be horrific.
9292
stdout: _T
9393
stderr: _T
94-
# type ignore on __init__ because the TypeVar can technically be unsolved, but see comment above
95-
def __init__(self, args: _CMD, returncode: int, stdout: _T | None = ..., stderr: _T | None = ...) -> None: ... # type: ignore
94+
# pyright ignore on __init__ because the TypeVar can technically be unsolved, but see comment above
95+
def __init__(
96+
self,
97+
args: _CMD,
98+
returncode: int,
99+
stdout: _T | None = ..., # pyright: ignore[reportInvalidTypeVarUse]
100+
stderr: _T | None = ..., # pyright: ignore[reportInvalidTypeVarUse]
101+
) -> None: ...
96102
def check_returncode(self) -> None: ...
97103
if sys.version_info >= (3, 9):
98104
def __class_getitem__(cls, item: Any) -> GenericAlias: ...

stdlib/typing.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
906906
# can go through.
907907
def setdefault(self, k: NoReturn, default: object) -> object: ...
908908
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
909-
def pop(self, k: NoReturn, default: _T = ...) -> object: ... # type: ignore
909+
def pop(self, k: NoReturn, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
910910
def update(self: _T, __m: _T) -> None: ...
911911
def __delitem__(self, k: NoReturn) -> None: ...
912912
def items(self) -> ItemsView[str, object]: ...

stdlib/typing_extensions.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
126126
# can go through.
127127
def setdefault(self, k: NoReturn, default: object) -> object: ...
128128
# Mypy plugin hook for 'pop' expects that 'default' has a type variable type.
129-
def pop(self, k: NoReturn, default: _T = ...) -> object: ... # type: ignore
129+
def pop(self, k: NoReturn, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse]
130130
def update(self: _T, __m: _T) -> None: ...
131131
def items(self) -> ItemsView[str, object]: ...
132132
def keys(self) -> KeysView[str]: ...

stdlib/weakref.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]):
8888
class KeyedRef(ref[_T], Generic[_KT, _T]):
8989
key: _KT
9090
# This __new__ method uses a non-standard name for the "cls" parameter
91-
def __new__(type: type[Self], ob: _T, callback: Callable[[_T], Any], key: _KT) -> Self: ... # type: ignore
91+
def __new__(type: type[Self], ob: _T, callback: Callable[[_T], Any], key: _KT) -> Self: ...
9292
def __init__(self, ob: _T, callback: Callable[[_T], Any], key: _KT) -> None: ...
9393

9494
class WeakKeyDictionary(MutableMapping[_KT, _VT]):

0 commit comments

Comments
 (0)