Skip to content

tempfile: Fix TypeVar usage #7939

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 10 commits into from
May 26, 2022
22 changes: 12 additions & 10 deletions stdlib/tempfile.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io
import os
import sys
from _typeshed import Self, WriteableBuffer
from _typeshed import Self, StrPath, WriteableBuffer
from collections.abc import Iterable, Iterator
from types import TracebackType
from typing import IO, Any, AnyStr, Generic, overload
Expand Down Expand Up @@ -380,20 +380,22 @@ class TemporaryDirectory(Generic[AnyStr]):
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...

# The overloads overlap, but they should still work fine.
@overload
def mkstemp() -> tuple[int, str]: ...
def mkstemp( # type: ignore[misc]
suffix: str | None = ..., prefix: str | None = ..., dir: _DirT[str] | None = ..., text: bool = ...
) -> tuple[int, str]: ...
@overload
def mkstemp(
suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: _DirT[AnyStr] | None = ..., text: bool = ...
) -> tuple[int, AnyStr]: ...
@overload
def mkdtemp() -> str: ...
@overload
def mkdtemp(suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: _DirT[AnyStr] | None = ...) -> AnyStr: ...
suffix: bytes | None = ..., prefix: bytes | None = ..., dir: _DirT[bytes] | None = ..., text: bool = ...
) -> tuple[int, bytes]: ...

# The overloads overlap, but they should still work fine.
@overload
def mktemp() -> str: ...
def mkdtemp(suffix: str | None = ..., prefix: str | None = ..., dir: _DirT[str] | None = ...) -> str: ... # type: ignore[misc]
@overload
def mktemp(suffix: AnyStr | None = ..., prefix: AnyStr | None = ..., dir: _DirT[AnyStr] | None = ...) -> AnyStr: ...
def mkdtemp(suffix: bytes | None = ..., prefix: bytes | None = ..., dir: _DirT[bytes] | None = ...) -> bytes: ...
def mktemp(suffix: str = ..., prefix: str = ..., dir: StrPath | None = ...) -> str: ...
def gettempdirb() -> bytes: ...
def gettempprefixb() -> bytes: ...
def gettempdir() -> str: ...
Expand Down