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

gh-92877: Advise to use typing.IO sparingly #92878

Closed
wants to merge 2 commits into from

Conversation

srittau
Copy link
Contributor

@srittau srittau commented May 17, 2022

No description provided.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While using Protocols works well for typeshed, I'm not sure it's the right advice for all typing users. Protocols are an advanced feature and the details are often tricky to get right. It's mostly fine for users to use IO/TextIO/BinaryIO within applications where they may not need to worry about exotic file-like objectts.

A friendlier approach could be along the lines of "Not all file-like types are recognized as instances of these types. If you encounter such types, consider using a Protocol instead."

@srittau
Copy link
Contributor Author

srittau commented May 17, 2022

While using Protocols works well for typeshed, I'm not sure it's the right advice for all typing users. Protocols are an advanced feature and the details are often tricky to get right. It's mostly fine for users to use IO/TextIO/BinaryIO within applications where they may not need to worry about exotic file-like objectts.

A friendlier approach could be along the lines of "Not all file-like types are recognized as instances of these types. If you encounter such types, consider using a Protocol instead."

Maybe it would be a good idea to provide slimmed down protocols, like those suggested in python/typing#564. I think we by now have a good sense for what methods are commonly accessed. We could then suggest to use those protocols.

@srittau
Copy link
Contributor Author

srittau commented Jun 3, 2022

I'm closing this for now while exploring other approaches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants