[mypyc] Add prefix to attributes of generator classes#19535
Merged
JukkaL merged 4 commits intopython:masterfrom Aug 11, 2025
Merged
[mypyc] Add prefix to attributes of generator classes#19535JukkaL merged 4 commits intopython:masterfrom
JukkaL merged 4 commits intopython:masterfrom
Conversation
JukkaL
reviewed
Jul 30, 2025
Collaborator
JukkaL
left a comment
There was a problem hiding this comment.
This still generates the compile error:
from typing import Iterator
def foo() -> Iterator[int]:
send = 1
yield send + 1
print(list(foo()))Once the above example works, also test the exception error message here:
from typing import Iterator
def foo() -> Iterator[int]:
if int():
send = 1
yield send + 1
print(list(foo()))e01469d to
988b762
Compare
for more information, see https://pre-commit.ci
JukkaL
approved these changes
Aug 11, 2025
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#1120
asyncfunctions 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 forGetAttrandSetAttrnodes in the IR.This is incorrect and led to the compilation error in the linked issue because the
sendmethod 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.