You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I understand correctly, as per the csv.writer docs , csvfile can be any object with a write() method, which means that things like io.BytesIO whose write accepts bytes-like object will fail typechecking
A minimal reproducer for this is as follows, and the type checking was done against mypy 0.770
and python 3.8.2
$ mypy --version
mypy 0.770
$ python --version
Python 3.8.2
$ mypy scratch.py
scratch.py:5: error: Argument 1 to "writer" has incompatible type "BytesIO"; expected "_Writer"
scratch.py:5: note: Following member(s) of "BytesIO" have conflicts:
scratch.py:5: note: Expected:
scratch.py:5: note: def write(self, s: str) -> Any
scratch.py:5: note: Got:
scratch.py:5: note: def write(self, Union[bytes, bytearray]) -> int
Found 1 error in 1 file (checked 1 source file)
Also note that this worked in mypy 0.760
$ mypy --version
mypy 0.760
$ mypy scratch.py
Success: no issues found in 1 source file
The text was updated successfully, but these errors were encountered:
deveshks
changed the title
"csv.writer.write" does not work for objects expecting something other than str in their write method
"csv.writer.write" does not work for objects expecting something other than "str" in their "write" method
May 15, 2020
Uh oh!
There was an error while loading. Please reload this page.
This was originally found when upgrading pip to
mypy 0.770
in pypa/pip#8235There was a change made to
_csv.pyi
in #3581 which hardcodes the input type of_Writer.write
tostr
typeshed/stdlib/2and3/_csv.pyi
Lines 44 to 45 in 6dca3f7
If I understand correctly, as per the csv.writer docs ,
csvfile can be any object with a write() method
, which means that things like io.BytesIO whose write acceptsbytes-like object
will fail typecheckingA minimal reproducer for this is as follows, and the type checking was done against
mypy 0.770
and
python 3.8.2
And the output is
Also note that this worked in
mypy 0.760
The text was updated successfully, but these errors were encountered: