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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid chaining is #2443

Closed
orsinium opened this issue Jul 4, 2022 · 10 comments
Closed

Forbid chaining is #2443

orsinium opened this issue Jul 4, 2022 · 10 comments
Assignees
Labels
good first issue Entrypoint to the project help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule

Comments

@orsinium
Copy link
Collaborator

orsinium commented Jul 4, 2022

Rule request

Thesis

Forbid ast.Is in ast.Compare.ops when it's size is not zero. For example:

a = None
a is None           # True, as expected
a is None is True   # False 馃
a is None == True   # False 馃
a is None is None   # True 馃く 

Reasoning

From the AST perspective, is is an operator and can be chained. That can lead to unexpected results when the author wanted to compare the result of a is b operation. Instead, Python will chain the operations and compare the last argument of the previous operation.

@orsinium orsinium added the rule request Adding a new rule label Jul 4, 2022
@orsinium
Copy link
Collaborator Author

orsinium commented Jul 4, 2022

Also, I think the same applies to in

@sobolevn
Copy link
Member

sobolevn commented Jul 4, 2022

Yes, totally.

@sobolevn sobolevn added help wanted Extra attention is needed level:starter Good for newcomers good first issue Entrypoint to the project labels Jul 4, 2022
@sobolevn sobolevn added this to the Version 0.17.0 aka Python3.10 milestone Jul 4, 2022
@JanaHafez1
Copy link

Hi, I'm new to contributing and would like to work on this issue.

@lensvol
Copy link
Collaborator

lensvol commented Oct 1, 2022

If there is no progress on this issue, then I would like to implement it.

@sobolevn
Copy link
Member

sobolevn commented Oct 1, 2022

Hi, @lensvol! Happy to see you :)

@lensvol
Copy link
Collaborator

lensvol commented Oct 2, 2022

@sobolevn You know me, can't stay away from a free T-shirt :)

lensvol added a commit to lensvol/wemake-python-styleguide that referenced this issue Oct 10, 2022
@lensvol
Copy link
Collaborator

lensvol commented Oct 10, 2022

Implemented in #2527, please review.

@adlizone
Copy link

If it is not resolved. I would like to work on this issue

@sobolevn
Copy link
Member

@adlizone feel free :)

@orsinium
Copy link
Collaborator Author

I think it is resolved in #2527, we just forgot to actualize the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Entrypoint to the project help wanted Extra attention is needed level:starter Good for newcomers rule request Adding a new rule
Projects
None yet
Development

No branches or pull requests

5 participants