-
Notifications
You must be signed in to change notification settings - Fork 258
What to do with IO, TextIO and BytesIO #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think somebody pointed out that it might better to have these classes live somewhere else than |
Do we want to make a package out of |
Based on #23, it seems that I don't have a very strong opinion on whether IO ABCs should live in |
Based on #23, let's put them in typing.io. But let's have a typing/init.py that pre-imports the io and re submodules (as well as defining all the other stuff that we want exported from typing, such as Sequence and List and TypeVar and Union etc.). |
Fixed in e2e6fc4 (along with pre-importing io and re). |
Mypy's
typing
has ABCsIO[AnyStr]
,TextIO
andBytesIO
for file-like objects.TextIO
andBytesIO
are subclasses ofIO[AnyStr]
. They have various issues, including these:IO[Any]
can be used to represent arbitrary file-like objects, but it doesn't support properties and methods only supported by text or binary files, but not by both. Maybe these should be added to theIO
ABC, so thatIO[Any]
could be used whenever we don't statically know whether a file is a text or a binary file (but the programmer may be able to predict this).TextIO
andBytesIO
or make them aliases ofIO[str]
andIO[bytes]
, respectively.write
method ofIO[bytes]
only acceptsbytes
objects, since there is no way in the type system make it more general (e.g., to also acceptbytearray
objects).BytesIO
can have the more general method type, however.The text was updated successfully, but these errors were encountered: