Skip to content

gh-102936: typing: document performance pitfalls of protocols decorated with @runtime_checkable #102937

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

Merged

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Mar 22, 2023

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Makes sense.

Copy link
Contributor

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! Had one suggestion for a different example of attribute

@@ -1584,16 +1584,31 @@ These are not used in annotations. They are building blocks for creating generic

assert isinstance(open('/some/file'), Closable)

@runtime_checkable
Copy link
Contributor

Choose a reason for hiding this comment

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

I think many users aren't too familiar with OSError's constructor / we can't use kwargs and it's unclear what the second argument is. Maybe we could use int and HasNumerator instead?

(I know it's not writeable, but OSError's errno also is maybe not writeable? Writing to errno doesn't affect repr)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was really struggling to think of a good example for this! I'll ponder some more and see if I can come up with something better...

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps unsurprisingly, not too many good cases of writeable attributes in stdlib. Maybe Thread.name? It's explicitly documented as something you can write to.

Copy link
Member Author

Choose a reason for hiding this comment

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

That works! I'll make the change tomorrow (it's late here)

@AlexWaygood AlexWaygood merged commit 58d2b30 into python:main Mar 23, 2023
@miss-islington
Copy link
Contributor

Thanks @AlexWaygood for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

@AlexWaygood AlexWaygood deleted the document-runtime_checkable-quite-bad branch March 23, 2023 18:18
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 23, 2023
…ecorated with `@runtime_checkable` (pythonGH-102937)

(cherry picked from commit 58d2b30)

Co-authored-by: Alex Waygood <[email protected]>
@bedevere-bot
Copy link

GH-102963 is a backport of this pull request to the 3.11 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 23, 2023
…ecorated with `@runtime_checkable` (pythonGH-102937)

(cherry picked from commit 58d2b30)

Co-authored-by: Alex Waygood <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Mar 23, 2023
@bedevere-bot
Copy link

GH-102964 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Mar 23, 2023
@AlexWaygood
Copy link
Member Author

Thanks all for the reviews!

miss-islington added a commit that referenced this pull request Mar 23, 2023
…ed with `@runtime_checkable` (GH-102937)

(cherry picked from commit 58d2b30)

Co-authored-by: Alex Waygood <[email protected]>
miss-islington added a commit that referenced this pull request Mar 23, 2023
…ed with `@runtime_checkable` (GH-102937)

(cherry picked from commit 58d2b30)

Co-authored-by: Alex Waygood <[email protected]>
Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this pull request Mar 27, 2023
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news topic-typing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants