Skip to content
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

Allow class/function calls in list assignments #29

Open
BPHarris opened this issue Feb 17, 2023 · 1 comment
Open

Allow class/function calls in list assignments #29

BPHarris opened this issue Feb 17, 2023 · 1 comment
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@BPHarris
Copy link
Collaborator

The following minimal example fails on rattr main but should pass. This fails as visit_ClassAssign expects that all assignments with a class in the RHS will be one-to-one.

Support for many-to-many may be out of scope (see footnote), but the simplest case below should pass.

class MyClass:
    pass

def in_init():
    my_list = [MyClass()]

def in_concat():
    my_list = []
    my_list += [MyClass()]

Footnote

In short the issue is that many-to-many involves implicit unpacking (which is runtime so out-of-scope) and in python we can get rather yucky with it, take this for example:

In [1]: class MyClass:
   ...:     def __new__(cls):
   ...:         return [1, 2]
   ...: 
   ...: a, b = [*MyClass()]

In [2]: a
Out[2]: 1

In [3]: b
Out[3]: 2
@BPHarris BPHarris added bug Something isn't working good first issue Good for newcomers labels Feb 17, 2023
@BPHarris BPHarris self-assigned this Feb 17, 2023
@BPHarris
Copy link
Collaborator Author

BPHarris commented Nov 7, 2024

Specifically the example code in the issue gives this failure:

image

When ideally we should visit the calls in the list, and give a warning if needed but not a fatal error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant