-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Typing: Document performance pitfalls of protocols decorated with @runtime_checkable
#102936
Labels
Comments
AlexWaygood
added a commit
that referenced
this issue
Mar 23, 2023
…ed with `@runtime_checkable` (#102937)
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Mar 23, 2023
…ecorated with `@runtime_checkable` (pythonGH-102937) (cherry picked from commit 58d2b30) Co-authored-by: Alex Waygood <[email protected]>
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Mar 23, 2023
…ecorated with `@runtime_checkable` (pythonGH-102937) (cherry picked from commit 58d2b30) Co-authored-by: Alex Waygood <[email protected]>
miss-islington
added a commit
that referenced
this issue
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 issue
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 issue
Mar 27, 2023
…ecorated with `@runtime_checkable` (python#102937)
warsaw
pushed a commit
to warsaw/cpython
that referenced
this issue
Apr 11, 2023
…ecorated with `@runtime_checkable` (python#102937)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Documentation
The following two calls look similar, but the second is dramatically slow compared to the first:
The reason for the slowness is because of
_ProtocolMeta.__instancecheck__
, which makes callingisinstance()
against any runtime-checkable protocol pretty slow. It's possible we can find ways of optimising_ProtocolMeta.__instancecheck__
, but whatever we do, it is likely to remain substantially slower to callisinstance()
against runtime-checkable protocols than it is to callisinstance()
against "normal" classes. This is often pretty surprising for users, so one of the consensus points in python/typing#1363 was that this should be better documented.Linked PRs
@runtime_checkable
#102937@runtime_checkable
(GH-102937) #102963@runtime_checkable
(GH-102937) #102964The text was updated successfully, but these errors were encountered: