Skip to content

Commit

Permalink
Merge pull request #3894 from hippo91/bug_pylint_3885
Browse files Browse the repository at this point in the history
Bug pylint 3885
  • Loading branch information
hippo91 committed Oct 24, 2020
2 parents acf39ac + ee15027 commit fed4438
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
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"

0 comments on commit fed4438

Please sign in to comment.