Visitar URL original
gh-92877: Advise to use typing.IO sparingly by srittau · Pull Request #92878 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20220519145804/https://github.com/python/cpython/pull/92878
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

srittau
Copy link
Contributor

@srittau srittau commented May 17, 2022

No description provided.

Doc/library/typing.rst Outdated Show resolved Hide resolved
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

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

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.

None yet

4 participants