Skip to content

Commit 630b49a

Browse files
srittauAlexWaygood
andauthored
Replace various Incompletes in stdlib (#11673)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 0cea0bc commit 630b49a

File tree

7 files changed

+49
-23
lines changed

7 files changed

+49
-23
lines changed

stdlib/importlib/resources/simple.pyi

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import abc
22
import sys
3-
from _typeshed import Incomplete, OpenBinaryMode, OpenTextMode, Unused
43
from collections.abc import Iterator
54
from io import TextIOWrapper
65
from typing import IO, Any, BinaryIO, Literal, NoReturn, overload
@@ -28,11 +27,19 @@ if sys.version_info >= (3, 11):
2827
def is_file(self) -> Literal[True]: ...
2928
def is_dir(self) -> Literal[False]: ...
3029
@overload
31-
def open(self, mode: OpenTextMode = "r", *args, **kwargs) -> TextIOWrapper: ...
30+
def open(
31+
self,
32+
mode: Literal["r"] = "r",
33+
encoding: str | None = None,
34+
errors: str | None = None,
35+
newline: str | None = None,
36+
line_buffering: bool = False,
37+
write_through: bool = False,
38+
) -> TextIOWrapper: ...
3239
@overload
33-
def open(self, mode: OpenBinaryMode, *args: Unused, **kwargs: Unused) -> BinaryIO: ...
40+
def open(self, mode: Literal["rb"]) -> BinaryIO: ...
3441
@overload
35-
def open(self, mode: str, *args: Incomplete, **kwargs) -> IO[Any]: ...
42+
def open(self, mode: str) -> IO[Any]: ...
3643
def joinpath(self, name: Never) -> NoReturn: ... # type: ignore[override]
3744

3845
class ResourceContainer(Traversable, metaclass=abc.ABCMeta):

stdlib/io.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ class TextIOWrapper(TextIOBase, TextIO): # type: ignore[misc] # incompatible d
179179
def __init__(
180180
self,
181181
buffer: _WrappedBuffer,
182-
encoding: str | None = ...,
183-
errors: str | None = ...,
184-
newline: str | None = ...,
185-
line_buffering: bool = ...,
186-
write_through: bool = ...,
182+
encoding: str | None = None,
183+
errors: str | None = None,
184+
newline: str | None = None,
185+
line_buffering: bool = False,
186+
write_through: bool = False,
187187
) -> None: ...
188188
# Equals the "buffer" argument passed in to the constructor.
189189
@property

stdlib/multiprocessing/resource_tracker.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ __all__ = ["ensure_running", "register", "unregister"]
66
class ResourceTracker:
77
def getfd(self) -> int | None: ...
88
def ensure_running(self) -> None: ...
9-
def register(self, name: Sized, rtype) -> None: ...
10-
def unregister(self, name: Sized, rtype) -> None: ...
9+
def register(self, name: Sized, rtype: str) -> None: ...
10+
def unregister(self, name: Sized, rtype: str) -> None: ...
1111

1212
_resource_tracker: ResourceTracker
1313
ensure_running = _resource_tracker.ensure_running

stdlib/multiprocessing/util.pyi

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import threading
22
from _typeshed import ConvertibleToInt, Incomplete, Unused
33
from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence
44
from logging import Logger, _Level as _LoggingLevel
5-
from typing import Any
5+
from typing import Any, Generic, TypeVar, overload
66

77
__all__ = [
88
"sub_debug",
@@ -22,6 +22,9 @@ __all__ = [
2222
"SUBWARNING",
2323
]
2424

25+
_T = TypeVar("_T")
26+
_R_co = TypeVar("_R_co", default=Any, covariant=True)
27+
2528
NOTSET: int
2629
SUBDEBUG: int
2730
DEBUG: int
@@ -42,13 +45,29 @@ def is_abstract_socket_namespace(address: str | bytes | None) -> bool: ...
4245
abstract_sockets_supported: bool
4346

4447
def get_temp_dir() -> str: ...
45-
def register_after_fork(obj, func: Callable[[Incomplete], object]) -> None: ...
48+
def register_after_fork(obj: _T, func: Callable[[_T], object]) -> None: ...
4649

47-
class Finalize:
50+
class Finalize(Generic[_R_co]):
51+
# "args" and "kwargs" are passed as arguments to "callback".
52+
@overload
53+
def __init__(
54+
self,
55+
obj: None,
56+
callback: Callable[..., _R_co],
57+
*,
58+
args: Sequence[Any] = (),
59+
kwargs: Mapping[str, Any] | None = None,
60+
exitpriority: int,
61+
) -> None: ...
62+
@overload
63+
def __init__(
64+
self, obj: None, callback: Callable[..., _R_co], args: Sequence[Any], kwargs: Mapping[str, Any] | None, exitpriority: int
65+
) -> None: ...
66+
@overload
4867
def __init__(
4968
self,
50-
obj: Incomplete | None,
51-
callback: Callable[..., Incomplete],
69+
obj: Any,
70+
callback: Callable[..., _R_co],
5271
args: Sequence[Any] = (),
5372
kwargs: Mapping[str, Any] | None = None,
5473
exitpriority: int | None = None,
@@ -59,7 +78,7 @@ class Finalize:
5978
_finalizer_registry: MutableMapping[Incomplete, Incomplete] = {},
6079
sub_debug: Callable[..., object] = ...,
6180
getpid: Callable[[], int] = ...,
62-
): ...
81+
) -> _R_co: ...
6382
def cancel(self) -> None: ...
6483
def still_active(self) -> bool: ...
6584

stdlib/typing.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class TypeVar:
170170
def __or__(self, right: Any) -> _SpecialForm: ...
171171
def __ror__(self, left: Any) -> _SpecialForm: ...
172172
if sys.version_info >= (3, 11):
173-
def __typing_subst__(self, arg): ...
173+
def __typing_subst__(self, arg: Any) -> Any: ...
174174

175175
# Used for an undocumented mypy feature. Does not exist at runtime.
176176
_promote = object()
@@ -221,7 +221,7 @@ if sys.version_info >= (3, 11):
221221
def __init__(self, name: str) -> None: ...
222222
def __iter__(self) -> Any: ...
223223
def __typing_subst__(self, arg: Never) -> Never: ...
224-
def __typing_prepare_subst__(self, alias, args): ...
224+
def __typing_prepare_subst__(self, alias: Any, args: Any) -> tuple[Any, ...]: ...
225225

226226
if sys.version_info >= (3, 10):
227227
@final
@@ -270,8 +270,8 @@ if sys.version_info >= (3, 10):
270270
@property
271271
def kwargs(self) -> ParamSpecKwargs: ...
272272
if sys.version_info >= (3, 11):
273-
def __typing_subst__(self, arg): ...
274-
def __typing_prepare_subst__(self, alias, args): ...
273+
def __typing_subst__(self, arg: Any) -> Any: ...
274+
def __typing_prepare_subst__(self, alias: Any, args: Any) -> tuple[Any, ...]: ...
275275

276276
def __or__(self, right: Any) -> _SpecialForm: ...
277277
def __ror__(self, left: Any) -> _SpecialForm: ...

stdlib/typing_extensions.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ class TypeVar:
413413
def __or__(self, right: Any) -> _SpecialForm: ...
414414
def __ror__(self, left: Any) -> _SpecialForm: ...
415415
if sys.version_info >= (3, 11):
416-
def __typing_subst__(self, arg): ...
416+
def __typing_subst__(self, arg: Any) -> Any: ...
417417

418418
@final
419419
class ParamSpec:

stdlib/xml/dom/xmlbuilder.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class DOMBuilder:
6060
def supportsFeature(self, name: str) -> bool: ...
6161
def canSetFeature(self, name: str, state: int) -> bool: ...
6262
# getFeature could return any attribute from an instance of `Options`
63-
def getFeature(self, name: str): ...
63+
def getFeature(self, name: str) -> Any: ...
6464
def parseURI(self, uri: str) -> ExpatBuilder | ExpatBuilderNS: ...
6565
def parse(self, input: DOMInputSource) -> ExpatBuilder | ExpatBuilderNS: ...
6666
# `input` and `cnode` argtypes for `parseWithContext` are unknowable

0 commit comments

Comments
 (0)