-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
stubs: false positiveType checkers report false errorsType checkers report false errorstopic: ioI/O related issuesI/O related issues
Description
The official documentation for TextIOWrapper implies that the underlying buffer is an instance of (or implements the interface of) io.BufferedIOBase, but typeshed annotates it as IO[bytes], leading to the following counterintuitive behavior:
# repro.py
import typing
from io import TextIOWrapper, BufferedIOBase
def badfunc(stream: BufferedIOBase) -> TextIOWrapper:
return TextIOWrapper(stream)
def goodfunc(stream: typing.IO[bytes]) -> TextIOWrapper:
return TextIOWrapper(stream)18:12 [snoopjedi@denton ~]
$ python3 -m mypy repro.py
repro.py:6: error: Argument 1 to "TextIOWrapper" has incompatible type "BufferedIOBase"; expected "IO[bytes]"
Found 1 error in 1 file (checked 1 source file)
This example is reduced from a question a user asked in the #python IRC channel on Libera.net, regarding this user code in rdflib.
Version information
18:12 [snoopjedi@denton ~]
$ python3 -m mypy --version
mypy 0.910
18:12 [snoopjedi@denton ~]
$ python3 -V
Python 3.8.10
aucampiaaucampia
Metadata
Metadata
Assignees
Labels
stubs: false positiveType checkers report false errorsType checkers report false errorstopic: ioI/O related issuesI/O related issues