This code generates a false positive, but type checked cleanly on mypy 1.11:
fromtypingimportIOfromshutilimportcopyfileobjf: IO[str]
copyfileobj(f, f) # Cannot infer type argument 1 of "copyfileobj"
I believe the reason is that the definition of IO.write changed in typeshed, and this triggered a mypy bug. Here's how IO.write is currently defined:
classIO(Iterator[AnyStr]):
...
@abstractmethod@overloaddefwrite(self: IO[bytes], s: ReadableBuffer, /) ->int: ...
@abstractmethod@overloaddefwrite(self, s: AnyStr, /) ->int: ...
This code generates a false positive, but type checked cleanly on mypy 1.11:
I believe the reason is that the definition of
IO.writechanged in typeshed, and this triggered a mypy bug. Here's howIO.writeis currently defined: