-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
open()
overloads mixes typing.IO
and io.IOBase
hierarchies
#6076
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
Given the response in #6077, I would assume the right approach is to rather move to typing.IO hierarchies then. |
All types returned by |
The core of the issue is this: #6061 - but if the solution is to just not use the io.BaseIO type hierarchy for typing, then I guess it is not really a problem. |
The reason why this all came up, I'm trying to type functions that should accept things returned by open, and then would pass them onto TextIOWrapper, and I was typing them using |
Closing this issue as all returned types do derive from typing.IO, and typing.IO should be used instead of |
@aucampia I agree. The typing documentation is lacking. I added better documentation for I/O as a todo item for our not-yet-written Best Practices document: python/typing#851. |
Currently the overloads for the
open
builtin usesio.IOBase
based types for specific cases (specificallyio.{TextIOWrapper,FileIO,BufferedRandom,BufferedWriter,BufferedReader}
), but for fallbacks it usestyping.IO
based types (specificallytyping.{BinaryIO,IO[Any]}
).The same is the case for
Path.open
andTraversable.open
.This would maybe not be a problem if the
io.IOBase
classes were considered subclasses, subtypes or implementations oftyping.IO
, but this is not the case. This can maybe be considered a problem on it's own, but it would still seem better to use a consistent approach for typing.The practical problem that this causes is that functions that should deal with all result from open will have to accept both
typing.IO
andio.IOBase
.Written for commit 2217ac8, but can also be seen in typeshed included with mypy 0.910.
The text was updated successfully, but these errors were encountered: