From 45c916e8d2761d7b8eb67c5f3db82500e29bb4ac Mon Sep 17 00:00:00 2001 From: Edgar Handal Date: Mon, 22 Mar 2021 20:30:22 -0500 Subject: [PATCH] Type fixes for tempfile.TemporaryDirectory (#5121) If no arguments are passed to the TemporaryDirectory constructor, then the class defaults to using str. Overload the __init__ function to cover this case. --- stdlib/tempfile.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/tempfile.pyi b/stdlib/tempfile.pyi index a2ef7724b..53ff56f1b 100644 --- a/stdlib/tempfile.pyi +++ b/stdlib/tempfile.pyi @@ -310,7 +310,10 @@ class SpooledTemporaryFile(IO[AnyStr]): def __next__(self) -> AnyStr: ... class TemporaryDirectory(Generic[AnyStr]): - name: str + name: AnyStr + @overload + def __init__(self: TemporaryDirectory[str], suffix: None = ..., prefix: None = ..., dir: None = ...) -> None: ... + @overload def __init__( self, suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[_DirT[AnyStr]] = ... ) -> None: ...