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

Bug pylint 3885 #3894

Merged
merged 6 commits into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ What's New in Pylint 2.6.1?
===========================
Release date: TBA

* Fix a false-positive emission of `no-self-use` and `unused-argument` for methods
of generic structural types (`Protocol[T]`)

Closes #3885

* Fix bug that lead to duplicate messages when using ``--jobs 2`` or more.

Close #3584
Expand Down
4 changes: 3 additions & 1 deletion pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
"abc.abstractclassmethod",
"abc.abstractstaticmethod",
}
TYPING_PROTOCOLS = frozenset({"typing.Protocol", "typing_extensions.Protocol"})
TYPING_PROTOCOLS = frozenset(
{"typing.Protocol", "typing_extensions.Protocol", ".Protocol"}
)
ITER_METHOD = "__iter__"
AITER_METHOD = "__aiter__"
NEXT_METHOD = "__next__"
Expand Down
22 changes: 22 additions & 0 deletions tests/functional/p/protocol_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,25 @@ def update(self, blob: bytes):

def digest(self) -> bytes:
...


Generic = typing.TypeVar("Generic")


class HasherGeneric(typing.Protocol[Generic]):
"""A hashing algorithm, e.g. :func:`hashlib.sha256`."""
def update(self, blob: bytes):
...
def digest(self) -> bytes:
...


class Protocol: #pylint:disable=too-few-public-methods
pass

class HasherFake(Protocol):
"""A hashing algorithm, e.g. :func:`hashlib.sha256`."""
def update(self, blob: bytes): # [no-self-use, unused-argument]
...
def digest(self) -> bytes: # [no-self-use]
...
3 changes: 3 additions & 0 deletions tests/functional/p/protocol_classes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
no-self-use:31:HasherFake.update:"Method could be a function"
unused-argument:31:HasherFake.update:"Unused argument 'blob'":INFERENCE
no-self-use:33:HasherFake.digest:"Method could be a function"