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

protection against self-assignment #2930

Closed
gitavk opened this issue May 22, 2019 · 4 comments · Fixed by #3010
Closed

protection against self-assignment #2930

gitavk opened this issue May 22, 2019 · 4 comments · Fixed by #3010
Assignees
Labels
Checkers Related to a checker Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors
Milestone

Comments

@gitavk
Copy link

gitavk commented May 22, 2019

Based on the SO question it can be good point to add the default check for the self-assignment.
For example

class Aclass:
    def __init__(self, attr=None, attr2=None):
        self.attr = attr
        self.attr2 = attr2

def new_a(attr, attr2):
    a_inst = Aclass()
    a_inst.attr2 = attr2
    # should be: a_inst.attr = attr, but have a typo
    attr = attr
    return a_inst
@PCManticore PCManticore added Checkers Related to a checker Good first issue Friendly and approachable by new contributors Enhancement ✨ Improvement to a component labels May 23, 2019
@PCManticore
Copy link
Contributor

Thanks, this would be good to have!

PCManticore added a commit that referenced this issue Jul 17, 2019
This check is emitted when we detect that a variable is assigned
to itself, which might indicate a potential bug in the code application.
Close #2930
PCManticore added a commit that referenced this issue Jul 17, 2019
This check is emitted when we detect that a variable is assigned
to itself, which might indicate a potential bug in the code application.
Close #2930
@chaoflow
Copy link

@PCManticore @gitavk The new check catches the following code as erroneous:

FOO = 1

class Bar:
    FOO = FOO

Is this intentional?

@PCManticore
Copy link
Contributor

Looks like an untreated edge case to me, thanks for the ping.

@PCManticore PCManticore reopened this Sep 25, 2019
@PCManticore PCManticore self-assigned this Sep 25, 2019
@PCManticore PCManticore added this to the Next minor release milestone Sep 25, 2019
@chaoflow
Copy link

@PCManticore Thank you for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Checkers Related to a checker Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants