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

[Pylint] Fixed false-positive on the rule PLW1641 (eq-without-hash) #10566

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ def __eq__(self, other):
return True

__hash__ = None

class SingleClass:
def __eq__(self, other):
return True

def __hash__(self):
return 7

class ChildClass(SingleClass):
def __eq__(self, other):
return True

__hash__ = SingleClass.__hash__
11 changes: 6 additions & 5 deletions crates/ruff_linter/src/rules/pylint/rules/eq_without_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,21 @@ fn has_eq_without_hash(body: &[Stmt]) -> bool {
let mut has_eq = false;
for statement in body {
match statement {
Stmt::Assign(ast::StmtAssign { targets, value, .. }) => {
Stmt::Assign(ast::StmtAssign { targets, .. }) => {
let [Expr::Name(ast::ExprName { id, .. })] = targets.as_slice() else {
continue;
};

// Check if `__hash__` was explicitly set to `None`, as in:
// Check if `__hash__` was explicitly set, as in:
// ```python
// class Class:
// class Class(SuperClass):
// def __eq__(self, other):
// return True
//
// __hash__ = None
// __hash__ = SuperClass.__hash__
// ```
if id == "__hash__" && value.is_none_literal_expr() {

if id == "__hash__" {
has_hash = true;
}
}
Expand Down