Skip to content

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

Closed
JukkaL opened this issue Jan 8, 2015 · 5 comments
Closed

What to do with IO, TextIO and BytesIO #36

JukkaL opened this issue Jan 8, 2015 · 5 comments

Comments

@JukkaL
Copy link
Contributor

JukkaL commented Jan 8, 2015

Mypy's typing has ABCs IO[AnyStr], TextIO and BytesIO for file-like objects. TextIO and BytesIO are subclasses of IO[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 the IO ABC, so that IO[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).
  • If we implement the above change, we may be able to remove TextIO and BytesIO or make them aliases of IO[str] and IO[bytes], respectively.
  • There is no way to represent readibility or writability of files. Maybe there should be separate types for readable, writable and readable+writable files.
  • The write method of IO[bytes] only accepts bytes objects, since there is no way in the type system make it more general (e.g., to also accept bytearray objects). BytesIO can have the more general method type, however.
@JukkaL
Copy link
Contributor Author

JukkaL commented Jan 8, 2015

I think somebody pointed out that it might better to have these classes live somewhere else than typing. One option is to add module typing.io for them (if we make typing a package).

@ambv
Copy link
Contributor

ambv commented Jan 8, 2015

Do we want to make a package out of typing? The contract already is to provide generics-enabled builtins (List) and ABCs (Sequence). IO/BytesIO/TextIO look like a good candidate for Python 3.5 ABCs anyway. typing would have them like any other.

@JukkaL
Copy link
Contributor Author

JukkaL commented Jan 9, 2015

Based on #23, it seems that typing will be a package.

I don't have a very strong opinion on whether IO ABCs should live in typing or typing.io. However, at least almost all of the other ABCs in typing are related to containers, so the IO-related ABCs don't fit in perfectly.

@gvanrossum
Copy link
Member

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.).

@ambv
Copy link
Contributor

ambv commented Jan 14, 2015

Fixed in e2e6fc4 (along with pre-importing io and re).

@ambv ambv closed this as completed Jan 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants