tempfile.mkdtemp() should return a str when passed no arguments. (#2893)

Otherwise, pytype expands `AnyStr` to `Union[str, bytes]`, leading
to spurious type errors later on.

* Mark the `dir` argument to mkdtemp as AnyStr.
This commit is contained in:
Rebecca Chen
2019-03-29 15:11:42 -07:00
committed by Sebastian Rittau
parent f7c00b8b33
commit 9b9ff64fc5

View File

@@ -5,7 +5,7 @@
import sys
from types import TracebackType
from typing import Any, AnyStr, Generic, IO, Iterable, Iterator, List, Optional, Tuple, Type
from typing import Any, AnyStr, Generic, IO, Iterable, Iterator, List, Optional, overload, Tuple, Type
# global variables
TMP_MAX: int
@@ -74,8 +74,11 @@ if sys.version_info >= (3, 5):
def mkstemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[AnyStr] = ...,
text: bool = ...) -> Tuple[int, AnyStr]: ...
@overload
def mkdtemp() -> str: ...
@overload
def mkdtemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ...,
dir: Optional[str] = ...) -> AnyStr: ...
dir: Optional[AnyStr] = ...) -> AnyStr: ...
def mktemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[AnyStr] = ...) -> AnyStr: ...
def gettempdirb() -> bytes: ...