Skip to content

Commit cb7742e

Browse files
tempfile: Fix TypeVar usage (#7939)
Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent c8f9abf commit cb7742e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

stdlib/tempfile.pyi

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io
22
import os
33
import sys
4-
from _typeshed import Self, WriteableBuffer
4+
from _typeshed import Self, StrPath, WriteableBuffer
55
from collections.abc import Iterable, Iterator
66
from types import TracebackType
77
from typing import IO, Any, AnyStr, Generic, overload
@@ -380,20 +380,22 @@ class TemporaryDirectory(Generic[AnyStr]):
380380
if sys.version_info >= (3, 9):
381381
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
382382

383+
# The overloads overlap, but they should still work fine.
383384
@overload
384-
def mkstemp() -> tuple[int, str]: ...
385+
def mkstemp( # type: ignore[misc]
386+
suffix: str | None = ..., prefix: str | None = ..., dir: _DirT[str] | None = ..., text: bool = ...
387+
) -> tuple[int, str]: ...
385388
@overload
386389
def mkstemp(
387-
suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: _DirT[AnyStr] | None = ..., text: bool = ...
388-
) -> tuple[int, AnyStr]: ...
389-
@overload
390-
def mkdtemp() -> str: ...
391-
@overload
392-
def mkdtemp(suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: _DirT[AnyStr] | None = ...) -> AnyStr: ...
390+
suffix: bytes | None = ..., prefix: bytes | None = ..., dir: _DirT[bytes] | None = ..., text: bool = ...
391+
) -> tuple[int, bytes]: ...
392+
393+
# The overloads overlap, but they should still work fine.
393394
@overload
394-
def mktemp() -> str: ...
395+
def mkdtemp(suffix: str | None = ..., prefix: str | None = ..., dir: _DirT[str] | None = ...) -> str: ... # type: ignore[misc]
395396
@overload
396-
def mktemp(suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: _DirT[AnyStr] | None = ...) -> AnyStr: ...
397+
def mkdtemp(suffix: bytes | None = ..., prefix: bytes | None = ..., dir: _DirT[bytes] | None = ...) -> bytes: ...
398+
def mktemp(suffix: str = ..., prefix: str = ..., dir: StrPath | None = ...) -> str: ...
397399
def gettempdirb() -> bytes: ...
398400
def gettempprefixb() -> bytes: ...
399401
def gettempdir() -> str: ...

0 commit comments

Comments
 (0)