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
{{ message }}
Repository navigation
Inconsistent type hints lead to bad type checks #1078
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
AnyIO version
4.12.1
Python version
3.14.2
What happened?
importtypingasTimportanyioasyncdefhash_stream(algo: str, stream: anyio.abc.ByteReceiveStream, **opts) ->bytes:
...
asyncdef_do_hash(file: anyio.AsyncFile[bytes], algo: str, meta: object):
# Don't context-manage the stream, it's the caller's job to close everythingT.reveal_type(file)
T.reveal_type(file.wrapped)
stream=anyio.streams.file.FileReadStream(file.wrapped)
digest=awaithash_stream(algo, stream)
setattr(meta, f"hash_{algo}", digest)
mypy output:
src/swiss_army_upload/junk_drawer/rsync.py:63: note: Revealed type is "anyio._core._fileio.AsyncFile[builtins.bytes]"
src/swiss_army_upload/junk_drawer/rsync.py:64: note: Revealed type is "typing.IO[builtins.bytes]"
src/swiss_army_upload/junk_drawer/rsync.py:65: error: Argument 1 to "FileReadStream" has incompatible type "IO[bytes]"; expected "BinaryIO" [arg-type]
Activity
Fix type hints in FileReadStream/FileWriteStream to accept IO[bytes]
Fix type hints: accept IO[bytes] instead of BinaryIO in file streams
Widened type annotations to accept IO[bytes] in file streams