-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reinstate checks from the python3 checker that are still useful for py3
Closes #5025
- Loading branch information
1 parent
d91ef18
commit ea937e4
Showing
16 changed files
with
66 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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,39 @@ | ||
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | ||
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE | ||
|
||
"""This is the remnant of the python3 checker. It was removed because | ||
the transition from python 2 to python3 is behind us, but some checks | ||
are still useful in python3 after all. | ||
See https://github.com/PyCQA/pylint/issues/5025 | ||
""" | ||
|
||
|
||
from pylint import checkers, interfaces | ||
from pylint.checkers import utils | ||
|
||
|
||
class Python3Checker(checkers.BaseChecker): | ||
|
||
__implements__ = interfaces.IAstroidChecker | ||
enabled = True | ||
name = "python3" | ||
|
||
msgs = { | ||
"W1641": ( | ||
"Implementing __eq__ without also implementing __hash__", | ||
"eq-without-hash", | ||
"Used when a class implements __eq__ but not __hash__. In Python 2, objects " | ||
"get object.__hash__ as the default implementation, in Python 3 objects get " | ||
"None as their default __hash__ implementation if they also implement __eq__.", | ||
), | ||
} | ||
|
||
@utils.check_messages("eq-without-hash") | ||
def visit_classdef(self, node): | ||
locals_and_methods = set(node.locals).union(x.name for x in node.mymethods()) | ||
if "__eq__" in locals_and_methods and "__hash__" not in locals_and_methods: | ||
self.add_message("eq-without-hash", node=node) | ||
|
||
|
||
def register(linter): | ||
linter.register_checker(Python3Checker(linter)) |
This file contains 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 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 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 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,11 @@ | ||
"""Regression test for #5025""" | ||
|
||
# pylint: disable=invalid-name,missing-docstring, too-few-public-methods | ||
|
||
|
||
class AClass: # [eq-without-hash] | ||
def __init__(self) -> None: | ||
self.x = 5 | ||
|
||
def __eq__(self, other: object) -> bool: | ||
return isinstance(other, AClass) and other.x == self.x |
This file contains 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 @@ | ||
eq-without-hash:6:0:11:62:AClass:Implementing __eq__ without also implementing __hash__:UNDEFINED |
This file contains 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 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
eq-without-hash:9:0:11:19:Child:Implementing __eq__ without also implementing __hash__:UNDEFINED | ||
missing-function-docstring:10:4:11:19:Child.__eq__:Missing function or method docstring:INFERENCE |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
invalid-name:3:0:3:13::"Constant name ""SOME_CONSTANT"" doesn't conform to camelCase naming style ('([^\\W\\dA-Z][^\\W_]*|__.*__)$' pattern)":HIGH | ||
eq-without-hash:10:0:19:79:MyClass:Implementing __eq__ without also implementing __hash__:UNDEFINED | ||
invalid-name:10:0:19:79:MyClass:"Class name ""MyClass"" doesn't conform to camelCase naming style ('[^\\W\\dA-Z][^\\W_]+$' pattern)":HIGH | ||
invalid-name:22:0:23:8:say_hello:"Function name ""say_hello"" doesn't conform to camelCase naming style ('([^\\W\\dA-Z][^\\W_]{2,}|__[^\\W\\dA-Z_]\\w+__)$' pattern)":HIGH |
This file contains 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 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 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 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