Skip to content

Commit 01d5e28

Browse files
authored
Fix miscellaneous invalid TypeVar usages (#8074)
1 parent 4941ac0 commit 01d5e28

File tree

7 files changed

+36
-19
lines changed

7 files changed

+36
-19
lines changed

stdlib/ctypes/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def POINTER(type: type[_CT]) -> type[pointer[_CT]]: ...
164164
class pointer(Generic[_CT], _PointerLike, _CData):
165165
_type_: type[_CT]
166166
contents: _CT
167-
def __init__(self, arg: _CT = ...) -> None: ...
167+
def __init__(self, arg: _CT) -> None: ...
168168
@overload
169169
def __getitem__(self, __i: int) -> _CT: ...
170170
@overload

stdlib/difflib.pyi

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ class Match(NamedTuple):
2828
size: int
2929

3030
class SequenceMatcher(Generic[_T]):
31+
@overload
32+
def __init__(self, isjunk: Callable[[_T], bool] | None, a: Sequence[_T], b: Sequence[_T], autojunk: bool = ...) -> None: ...
33+
@overload
34+
def __init__(self, *, a: Sequence[_T], b: Sequence[_T], autojunk: bool = ...) -> None: ...
35+
@overload
3136
def __init__(
32-
self, isjunk: Callable[[_T], bool] | None = ..., a: Sequence[_T] = ..., b: Sequence[_T] = ..., autojunk: bool = ...
37+
self: SequenceMatcher[str],
38+
isjunk: Callable[[str], bool] | None = ...,
39+
a: Sequence[str] = ...,
40+
b: Sequence[str] = ...,
41+
autojunk: bool = ...,
3342
) -> None: ...
3443
def set_seqs(self, a: Sequence[_T], b: Sequence[_T]) -> None: ...
3544
def set_seq1(self, a: Sequence[_T]) -> None: ...

stdlib/mailbox.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ class Mailbox(Generic[_MessageT]):
4646

4747
_path: bytes | str # undocumented
4848
_factory: Callable[[IO[Any]], _MessageT] | None # undocumented
49-
def __init__(
50-
self, path: StrOrBytesPath, factory: Callable[[IO[Any]], _MessageT] | None = ..., create: bool = ...
51-
) -> None: ...
49+
@overload
50+
def __init__(self, path: StrOrBytesPath, factory: Callable[[IO[Any]], _MessageT], create: bool = ...) -> None: ...
51+
@overload
52+
def __init__(self, path: StrOrBytesPath, factory: None = ..., create: bool = ...) -> None: ...
5253
@abstractmethod
5354
def add(self, message: _MessageData) -> str: ...
5455
@abstractmethod

stdlib/multiprocessing/shared_memory.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from _typeshed import Self
33
from collections.abc import Iterable
4-
from typing import Any, Generic, TypeVar
4+
from typing import Any, Generic, TypeVar, overload
55

66
if sys.version_info >= (3, 9):
77
from types import GenericAlias
@@ -23,7 +23,10 @@ class SharedMemory:
2323

2424
class ShareableList(Generic[_SLT]):
2525
shm: SharedMemory
26-
def __init__(self, sequence: Iterable[_SLT] | None = ..., *, name: str | None = ...) -> None: ...
26+
@overload
27+
def __init__(self, sequence: None = ..., *, name: str | None = ...) -> None: ...
28+
@overload
29+
def __init__(self, sequence: Iterable[_SLT], *, name: str | None = ...) -> None: ...
2730
def __getitem__(self, position: int) -> _SLT: ...
2831
def __setitem__(self, position: int, value: _SLT) -> None: ...
2932
def __reduce__(self: Self) -> tuple[Self, tuple[_SLT, ...]]: ...

stdlib/tempfile.pyi

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,25 +355,27 @@ class TemporaryDirectory(Generic[AnyStr]):
355355
@overload
356356
def __init__(
357357
self: TemporaryDirectory[str],
358-
suffix: None = ...,
359-
prefix: None = ...,
360-
dir: None = ...,
358+
suffix: str | None = ...,
359+
prefix: str | None = ...,
360+
dir: StrPath | None = ...,
361361
ignore_cleanup_errors: bool = ...,
362362
) -> None: ...
363363
@overload
364364
def __init__(
365-
self,
366-
suffix: AnyStr | None = ...,
367-
prefix: AnyStr | None = ...,
368-
dir: GenericPath[AnyStr] | None = ...,
365+
self: TemporaryDirectory[bytes],
366+
suffix: bytes | None = ...,
367+
prefix: bytes | None = ...,
368+
dir: BytesPath | None = ...,
369369
ignore_cleanup_errors: bool = ...,
370370
) -> None: ...
371371
else:
372372
@overload
373-
def __init__(self: TemporaryDirectory[str], suffix: None = ..., prefix: None = ..., dir: None = ...) -> None: ...
373+
def __init__(
374+
self: TemporaryDirectory[str], suffix: str | None = ..., prefix: str | None = ..., dir: StrPath | None = ...
375+
) -> None: ...
374376
@overload
375377
def __init__(
376-
self, suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: GenericPath[AnyStr] | None = ...
378+
self: TemporaryDirectory[bytes], suffix: bytes | None = ..., prefix: bytes | None = ..., dir: BytesPath | None = ...
377379
) -> None: ...
378380

379381
def cleanup(self) -> None: ...

stubs/flake8-plugin-utils/flake8_plugin_utils/plugin.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
22
import ast
33
from collections.abc import Iterable, Iterator
4-
from typing import Any, Generic, TypeVar
4+
from typing import Any, Generic, TypeVar, overload
55
from typing_extensions import TypeAlias
66

77
FLAKE8_ERROR: TypeAlias = tuple[int, int, str, type[Any]]
@@ -18,7 +18,10 @@ class Error:
1818

1919
class Visitor(ast.NodeVisitor, Generic[TConfig]):
2020
errors: list[Error]
21-
def __init__(self, config: TConfig | None = ...) -> None: ...
21+
@overload
22+
def __init__(self, config: None = ...) -> None: ...
23+
@overload
24+
def __init__(self, config: TConfig) -> None: ...
2225
@property
2326
def config(self) -> TConfig: ...
2427
def error_from_node(self, error: type[Error], node: ast.AST, **kwargs: Any) -> None: ...

tests/stubtest_allowlists/py3_common.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ ctypes.memset # CFunctionType
8888
ctypes.pointer # imported C function
8989
ctypes.string_at # docstring argument name is wrong
9090
ctypes.wstring_at # docstring argument name is wrong
91-
difflib.SequenceMatcher.__init__ # mypy default value for generic parameter issues. See https://github.com/python/mypy/issues/3737
9291
distutils.command.bdist_packager # It exists in docs as package name but not in code except as a mention in a comment.
9392
distutils.version.Version._cmp # class should have declared this
9493
distutils.version.Version.parse # class should have declared this

0 commit comments

Comments
 (0)