-
-
Notifications
You must be signed in to change notification settings - Fork 2k
_TemporaryFileWrapper[bytes] somehow isn't a BinaryIO #7843
Copy link
Copy link
Closed
Description
With this test file repro.py:
import tempfile
from typing import BinaryIO
my_var: BinaryIO = tempfile.NamedTemporaryFile()I get this error from mypy repro.py:
repro.py:4:20: error: Incompatible types in assignment (expression has type "_TemporaryFileWrapper[bytes]", variable has type "BinaryIO") [assignment]
my_var: BinaryIO = tempfile.NamedTemporaryFile()
^
Found 1 error in 1 file (checked 1 source file)
This is with mypy version 0.941.
The NamedTemporaryFile() docs say that it "operates exactly as TemporaryFile() does", save for always having a name, and TemporaryFile() is documented to return a file-like object and to default to binary mode.
If BinaryIO is meant to represent a binary-mode file-like object, then there's something wrong with the type annotations if it's not able to match the return value of NamedTemporaryFile().
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels