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

Do not diagnose no-self-use or unused-argument for methods of generic structural types (Protocol[T]) #3885

Closed
jmehnle opened this issue Oct 8, 2020 · 1 comment · Fixed by #3894
Assignees
Labels
Bug 🪲 Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@jmehnle
Copy link

jmehnle commented Oct 8, 2020

This is a follow-up to #3002, which addressed the basic issue, but there's a special case that is still broken: when a protocol class is a generic, i.e., it inherits not simply from Protocol but from Protocol[T] or some other generic form of Protocol.

Steps to reproduce

import typing_extensions as tex
from typing import TypeVar

T = TypeVar("T")

@tex.runtime
class Hasher(tex.Protocol[T]):
    """A hashing algorithm, e.g. :func:`hashlib.sha256`."""
    def update(self, bs: bytes):
        ...
    def digest(self) -> bytes:
        ...

Current behavior

************* Module pylinttest
pylinttest.py:9:21: W0613: Unused argument 'bs' (unused-argument)
pylinttest.py:9:4: R0201: Method could be a function (no-self-use)
pylinttest.py:11:4: R0201: Method could be a function (no-self-use)
pylinttest.py:2:0: C0411: standard import "from typing import TypeVar" should be placed before "import typing_extensions as tex" (wrong-import-order)

Expected behavior

No diagnostics.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.7.9 (default, Sep  6 2020, 13:20:25)
[Clang 11.0.3 (clang-1103.0.32.62)]
@hippo91
Copy link
Contributor

hippo91 commented Oct 10, 2020

@jmehnle thanks for the report. It makes sense and i can reproduce it.

@hippo91 hippo91 self-assigned this Oct 10, 2020
@hippo91 hippo91 added Bug 🪲 Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code labels Oct 10, 2020
@hippo91 hippo91 mentioned this issue Oct 11, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants