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

Add regression test for no-member with generic base class #4471

Merged
merged 1 commit into from
May 30, 2021
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
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ modules are added.
* ``logging-format-interpolation`` and ``logging-not-lazy``, now works on logger
class created from renamed logging import following an upgrade in astroid.

* Fix false-positive ``no-member`` with generic base class

Closes PyCQA/astroid#942


What's New in Pylint 2.8.2?
===========================
Expand Down
20 changes: 19 additions & 1 deletion tests/functional/t/typing_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# https://github.com/PyCQA/pylint/issues/2822
# Base should be subscriptable, even with ABCMeta as metaclass
from abc import ABCMeta
from abc import ABC, ABCMeta
from typing import Generic, TypeVar

T = TypeVar("T")
Expand All @@ -12,3 +12,21 @@ class Base(Generic[T], metaclass=ABCMeta):

class Impl(Base[str]):
"""Impl"""


# https://github.com/PyCQA/astroid/issues/942
Anything = TypeVar("Anything")
MoreSpecific = TypeVar("MoreSpecific", str, int)

class A(ABC, Generic[Anything]):
def a_method(self) -> None: # pylint: disable=no-self-use
print("hello")

class B(A[MoreSpecific]):
pass

class C(B[str]):
pass

c = C()
c.a_method() # should NOT emit `no-member` error