Skip to content

Comments

WPS345: forbid symmetric bitwise operations (#3593)#3598

Open
j2cry wants to merge 2 commits intowemake-services:masterfrom
j2cry:issue-3593
Open

WPS345: forbid symmetric bitwise operations (#3593)#3598
j2cry wants to merge 2 commits intowemake-services:masterfrom
j2cry:issue-3593

Conversation

@j2cry
Copy link
Contributor

@j2cry j2cry commented Feb 10, 2026

I have made things!

This forbids symmetric bitwise operations of constants.

Checklist

  • I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
  • I have created at least one test case for the changes I have made
  • I have updated the documentation for the changes I have made
  • I have added my changes to the CHANGELOG.md

Related issues

Refs #3593

@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b8ed2f3) to head (30ffd99).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #3598   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          368       368           
  Lines        12255     12291   +36     
  Branches       846       853    +7     
=========================================
+ Hits         12255     12291   +36     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@j2cry
Copy link
Contributor Author

j2cry commented Feb 15, 2026

@sobolevn can you review it, please?

'-~8 ^ -~8',
'+7 & +++7',
'-~-7 | -~-7',
'(not not --7) ^ 7',
Copy link
Member

Choose a reason for hiding this comment

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

Can you please test -7 ^ 7? Should it raise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It won't raise, because this expression is asymmetric.
In general, an expression n ^ -n, as well as for & and | operators, requires calculation, i.e.

7 ^ -7 == -2
80 | -80 == -16
52 & -52 == 4

I think this can be used in some very specific logic. While n ^ n is always 0, and n & n, n | n is always n.

- Fixes false positive `WPS457` for ``while True`` loop with ``await`` expressions, #3753
- Fixes the false positive `WPS617` by assigning a function that receives a lambda expression as a parameter.
- Fixes false positive `WPS430` for whitelisted nested functions, #3589
- Fixes `WPS345` to forbid symmetric bitwise operations, #3593
Copy link
Member

Choose a reason for hiding this comment

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

This is not a fix, it is a new feature.

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.

2 participants