[mypyc] Add prefix to attributes of generator classes #19535
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#1120
async
functions were recently changed to be represented as generator classes in the IR. Their parameters are represented as attributes in those classes.There are several methods added to every generator class by the compiler, one of those is called
send
. If there is also a parameter calledsend
, mypyc assumes that the method is a property getter/setter and inserts method calls in the generated code forGetAttr
andSetAttr
nodes in the IR.This is incorrect and led to the compilation error in the linked issue because the
send
method of generator classes takes one more argument than a property getter would.The name clash is fixed by adding a prefix
__mypyc_generator_attribute__
to attribute names derived from parameters, which should ensure that argument references are not converted into method calls.