Skip to content
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

Include all file object operations in IO[AnyStr]? #163

Closed
gvanrossum opened this issue Apr 25, 2016 · 2 comments
Closed

Include all file object operations in IO[AnyStr]? #163

gvanrossum opened this issue Apr 25, 2016 · 2 comments

Comments

@gvanrossum
Copy link
Member

From python/mypy#338 -- not sure if this is still a good idea, but I'm moving all stubs-related mypy issues here if I'm not sure I can close them.

Currently the typing.IO[AnyStr] ABC only has operations that are valid for both binary and text files. This is sometimes awkward. Potentially add the entire file object interface to IO[AnyStr] so that IO[Any] supports both the text and binary file interfaces. We might then be able to get rid of TextIO and BinaryIO classes. This would simplify the programming model at the cost of some type checking precision. However, some code that is currently not statically typable would be (more) typable, so there might actually even be a net benefit in static typing precision.

@JukkaL
Copy link
Contributor

JukkaL commented May 16, 2016

See also discussion in python/mypy#1472. We could perhaps use something like the constraint-based approach proposed there to enforce that only the correct set of methods are available based on the value of a type variable. So binary-only methods would only be available on IO[bytes] and IO[Any], and text-only methods would only be available on IO[str] and IO[Any]. By having something like this, we'd get the precise type checking of the current approach with a simpler class hierarchy.

(I don't know whether this would be practical to implement, but it might well be.)

@JelleZijlstra
Copy link
Member

typing.IO currently has a long list of methods, and the issue has no concrete list of methods that should be added to IO. I don't think there's anything concrete to do here now; let's reopen if there's concrete code samples that could be helped by a change in the IO stubs.

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