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, because deprecated isn'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.
Creating an instance of the class itself (not of a subclass) issues the warning, before __new__ or
__init__ run. This is done in the native constructor and in tp_new. A class with a built-in base
class (an exception, for example) gets a tp_new for this, since it otherwise inherits it.
Creating a subclass issues the warning. The class gets an __init_subclass__ that warns and calls the
next 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.
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
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, because deprecated isn'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:
__init__ run. This is done in the native constructor and in tp_new. A class with a built-in base
class (an exception, for example) gets a tp_new for this, since it otherwise inherits it.
next 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.