-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Python: Modernize 3 quality queries for comparison methods #20038
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
Open
joefarebrother
wants to merge
15
commits into
github:main
Choose a base branch
from
joefarebrother:python-qual-comparison
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fccdc30
Modernize incomplete ordering query
joefarebrother e71af8f
Move to subfolder
joefarebrother 4c5c4e0
Move inconsistentEquality and equals-hash-mismatch to subfolder
joefarebrother eb1b5a3
Modernize inconsistent equality
joefarebrother a687b60
Modernise equals-hash-mismatch
joefarebrother 8fb9bdd
move equals attr test to equals attr folder
joefarebrother 083d258
Add/update unit tests
joefarebrother 843a6c8
Remove total order check from equals not equals (doesn't make sense t…
joefarebrother 58f503d
Update docs for incomplete ordering + inconsistent hashing
joefarebrother ea48fcc
Update doc for equalsNotEquals
joefarebrother 61af4e4
Add changenote and update integraion test output
joefarebrother f784bb0
Fix qldoc errors + typos
joefarebrother 0f04a8b
Update integration test output
joefarebrother 15115f5
Remove old tests
joefarebrother 3a27758
Remove old py2-specific tests
joefarebrother File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update doc for equalsNotEquals
- Loading branch information
commit ea48fcca8f55b76ed0383182734363b385c9b4cf
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
python/ql/src/Classes/Comparisons/examples/EqualsOrNotEquals.py
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
python/ql/src/Classes/Comparisons/examples/EqualsOrNotEquals1.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class A: | ||
def __init__(self, a): | ||
self.a = a | ||
|
||
# BAD: ne is defined, but not eq. | ||
def __ne__(self, other): | ||
if not isinstance(other, A): | ||
return NotImplemented | ||
return self.a != other.a | ||
|
||
x = A(1) | ||
y = A(1) | ||
|
||
print(x == y) # Prints False (potentially unexpected - object identity is used) | ||
print(x != y) # Prints False |
21 changes: 21 additions & 0 deletions
21
python/ql/src/Classes/Comparisons/examples/EqualsOrNotEquals2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class B: | ||
def __init__(self, b): | ||
self.b = b | ||
|
||
def __eq__(self, other): | ||
return self.b == other.b | ||
|
||
def __ne__(self, other): | ||
return self.b != other.b | ||
|
||
class C(B): | ||
def __init__(self, b, c): | ||
super().init(b) | ||
joefarebrother marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.c = c | ||
|
||
# BAD: eq is defined, but != will use superclass ne method, which is not consistent | ||
def __eq__(self, other): | ||
return self.b == other.b and self.c == other.c | ||
|
||
print(C(1,2) == C(1,3)) # Prints False | ||
print(C(1,2) != C(1,3)) # Prints False (potentially unexpected) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.