Skip to content

Fix miscellaneous invalid TypeVar usages #8074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def POINTER(type: type[_CT]) -> type[pointer[_CT]]: ...
class pointer(Generic[_CT], _PointerLike, _CData):
_type_: type[_CT]
contents: _CT
def __init__(self, arg: _CT = ...) -> None: ...
def __init__(self, arg: _CT) -> None: ...
@overload
def __getitem__(self, __i: int) -> _CT: ...
@overload
Expand Down
11 changes: 10 additions & 1 deletion stdlib/difflib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ class Match(NamedTuple):
size: int

class SequenceMatcher(Generic[_T]):
@overload
def __init__(self, isjunk: Callable[[_T], bool] | None, a: Sequence[_T], b: Sequence[_T], autojunk: bool = ...) -> None: ...
@overload
def __init__(self, *, a: Sequence[_T], b: Sequence[_T], autojunk: bool = ...) -> None: ...
@overload
def __init__(
self, isjunk: Callable[[_T], bool] | None = ..., a: Sequence[_T] = ..., b: Sequence[_T] = ..., autojunk: bool = ...
self: SequenceMatcher[str],
isjunk: Callable[[str], bool] | None = ...,
a: Sequence[str] = ...,
b: Sequence[str] = ...,
autojunk: bool = ...,
) -> None: ...
def set_seqs(self, a: Sequence[_T], b: Sequence[_T]) -> None: ...
def set_seq1(self, a: Sequence[_T]) -> None: ...
Expand Down
7 changes: 4 additions & 3 deletions stdlib/mailbox.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ class Mailbox(Generic[_MessageT]):

_path: bytes | str # undocumented
_factory: Callable[[IO[Any]], _MessageT] | None # undocumented
def __init__(
self, path: StrOrBytesPath, factory: Callable[[IO[Any]], _MessageT] | None = ..., create: bool = ...
) -> None: ...
@overload
def __init__(self, path: StrOrBytesPath, factory: Callable[[IO[Any]], _MessageT], create: bool = ...) -> None: ...
@overload
def __init__(self, path: StrOrBytesPath, factory: None = ..., create: bool = ...) -> None: ...
@abstractmethod
def add(self, message: _MessageData) -> str: ...
@abstractmethod
Expand Down
7 changes: 5 additions & 2 deletions stdlib/multiprocessing/shared_memory.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from _typeshed import Self
from collections.abc import Iterable
from typing import Any, Generic, TypeVar
from typing import Any, Generic, TypeVar, overload

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

class ShareableList(Generic[_SLT]):
shm: SharedMemory
def __init__(self, sequence: Iterable[_SLT] | None = ..., *, name: str | None = ...) -> None: ...
@overload
def __init__(self, sequence: None = ..., *, name: str | None = ...) -> None: ...
@overload
def __init__(self, sequence: Iterable[_SLT], *, name: str | None = ...) -> None: ...
def __getitem__(self, position: int) -> _SLT: ...
def __setitem__(self, position: int, value: _SLT) -> None: ...
def __reduce__(self: Self) -> tuple[Self, tuple[_SLT, ...]]: ...
Expand Down
20 changes: 11 additions & 9 deletions stdlib/tempfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -355,25 +355,27 @@ class TemporaryDirectory(Generic[AnyStr]):
@overload
def __init__(
self: TemporaryDirectory[str],
suffix: None = ...,
prefix: None = ...,
dir: None = ...,
suffix: str | None = ...,
prefix: str | None = ...,
dir: StrPath | None = ...,
ignore_cleanup_errors: bool = ...,
) -> None: ...
@overload
def __init__(
self,
suffix: AnyStr | None = ...,
prefix: AnyStr | None = ...,
dir: GenericPath[AnyStr] | None = ...,
self: TemporaryDirectory[bytes],
suffix: bytes | None = ...,
prefix: bytes | None = ...,
dir: BytesPath | None = ...,
ignore_cleanup_errors: bool = ...,
) -> None: ...
else:
@overload
def __init__(self: TemporaryDirectory[str], suffix: None = ..., prefix: None = ..., dir: None = ...) -> None: ...
def __init__(
self: TemporaryDirectory[str], suffix: str | None = ..., prefix: str | None = ..., dir: StrPath | None = ...
) -> None: ...
@overload
def __init__(
self, suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: GenericPath[AnyStr] | None = ...
self: TemporaryDirectory[bytes], suffix: bytes | None = ..., prefix: bytes | None = ..., dir: BytesPath | None = ...
) -> None: ...

def cleanup(self) -> None: ...
Expand Down
7 changes: 5 additions & 2 deletions stubs/flake8-plugin-utils/flake8_plugin_utils/plugin.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import ast
from collections.abc import Iterable, Iterator
from typing import Any, Generic, TypeVar
from typing import Any, Generic, TypeVar, overload
from typing_extensions import TypeAlias

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

class Visitor(ast.NodeVisitor, Generic[TConfig]):
errors: list[Error]
def __init__(self, config: TConfig | None = ...) -> None: ...
@overload
def __init__(self, config: None = ...) -> None: ...
@overload
def __init__(self, config: TConfig) -> None: ...
@property
def config(self) -> TConfig: ...
def error_from_node(self, error: type[Error], node: ast.AST, **kwargs: Any) -> None: ...
Expand Down
1 change: 0 additions & 1 deletion tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ ctypes.memset # CFunctionType
ctypes.pointer # imported C function
ctypes.string_at # docstring argument name is wrong
ctypes.wstring_at # docstring argument name is wrong
difflib.SequenceMatcher.__init__ # mypy default value for generic parameter issues. See https://github.com/python/mypy/issues/3737
distutils.command.bdist_packager # It exists in docs as package name but not in code except as a mention in a comment.
distutils.version.Version._cmp # class should have declared this
distutils.version.Version.parse # class should have declared this
Expand Down