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

[SIM909] Avoid reflexive assignment #114

Closed
rpdelaney opened this issue Mar 17, 2022 · 3 comments · Fixed by #121
Closed

[SIM909] Avoid reflexive assignment #114

rpdelaney opened this issue Mar 17, 2022 · 3 comments · Fixed by #121
Assignees
Labels
enhancement New feature or request

Comments

@rpdelaney
Copy link

Explanation

Assigning a name to itself is a no-op and should be eliminated.

Example

# Bad
foo = foo

# Good
# (nothing)

# Bad
foo = foo = 42

# Good
foo = 42
@rpdelaney rpdelaney added the enhancement New feature or request label Mar 17, 2022
@MartinThoma MartinThoma changed the title [New Rule] Avoid reflexive assignment [SIM909] Avoid reflexive assignment Mar 28, 2022
@MartinThoma
Copy link
Owner

Thank you for the idea! This will be called SIM909 for the trial period. Once it's through the trial period, it will be called SIM124.

@MartinThoma
Copy link
Owner

Example 1: foo = foo

$ python -m astpretty --no-show-offsets /dev/stdin <<< `cat example.py`
Module(
    body=[
        Assign(
            targets=[Name(id='foo', ctx=Store())],
            value=Name(id='foo', ctx=Load()),
            type_comment=None,
        ),
    ],
    type_ignores=[],
)

@MartinThoma
Copy link
Owner

Example 2: foo = foo = 42

$ python -m astpretty --no-show-offsets /dev/stdin <<< `cat example.py`
Module(
    body=[
        Assign(
            targets=[
                Name(id='foo', ctx=Store()),
                Name(id='foo', ctx=Store()),
            ],
            value=Constant(value=42, kind=None),
            type_comment=None,
        ),
    ],
    type_ignores=[],
)

MartinThoma added a commit that referenced this issue Mar 28, 2022
MartinThoma added a commit that referenced this issue Mar 28, 2022
MartinThoma added a commit that referenced this issue Mar 28, 2022
MartinThoma added a commit that referenced this issue Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants