Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes mypyc/mypyc#1245.
This builds on #22163 and uses its helpers, so the first commit here is that PR. Only the second commit
is new.
A class decorated with
@deprecated("...")(PEP 702) is compiled as a non-native class, becausedeprecatedisn't one of the class decorators that native classes support. Nothing reports this, and the class gets much slower: 213 ns instead of 17 ns per iteration for a method call and an attribute read in a compiled loop.Calling the runtime decorator on a native class can't work, since it replaces
__new__on the class. With this PR mypyc doesn't call it. The class stays native and does itself what the decorator would arrange:__deprecated__is set on the class.__new__or__init__run. This is done in the native constructor and intp_new. A class with a built-in baseclass (an exception, for example) gets a
tp_newfor this, since it otherwise inherits it.__init_subclass__that warns and calls thenext one. If the class defines
__init_subclass__, the warning is compiled into that method instead,with the mechanism from [mypyc] Support @deprecated on functions and methods #22163.