Skip to content

[mypyc] Add prefix to attributes of generator classes #19535

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

p-sawicki
Copy link
Collaborator

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 called send, mypyc assumes that the method is a property getter/setter and inserts method calls in the generated code for GetAttr and SetAttr 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.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 1.17.0 breaks build process on Apple Silicon
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy