Skip to content

Commit

Permalink
Add functional test demonstrating issue with type introspection
Browse files Browse the repository at this point in the history
  • Loading branch information
kriek committed Oct 10, 2022
1 parent cd1ddff commit 5951048
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/functional/n/no/no_member_type_introspection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Tests for no-member when type(self)() is returned by a method."""
# pylint: disable=fixme,missing-class-docstring,missing-function-docstring,too-few-public-methods

# Test for: https://github.com/PyCQA/pylint/issues/7464
# TODO: the findings are false positives/negatives, see above link to issue.

from . import no_member_type_introspection_base as ext


class ExtBaseA(ext.Base):
def only_in_a(self):
pass


class ExtBaseB(ext.Base):
def only_in_b(self):
pass


a = ExtBaseA()
new_a = a.return_type()
new_a.only_in_a()
new_a.only_in_b() # [no-member]


b = ExtBaseB()
new_b = b.return_type()
new_b.only_in_a() # no-member false negative
new_b.only_in_b() # [no-member] false positive


class Base:
def return_type(self):
return type(self)()


class LocalBaseA(Base):
def only_in_a(self):
pass


class LocalBaseB(Base):
def only_in_b(self):
pass


a = LocalBaseA()
new_a = a.return_type()
new_a.only_in_a() # [no-member] false positive
new_a.only_in_b() # [no-member]


b = LocalBaseB()
new_b = b.return_type()
new_b.only_in_a() # [no-member]
new_b.only_in_b() # [no-member] false positive
6 changes: 6 additions & 0 deletions tests/functional/n/no/no_member_type_introspection.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
no-member:23:0:23:15::Instance of 'ExtBaseA' has no 'only_in_b' member; maybe 'only_in_a'?:INFERENCE
no-member:29:0:29:15::Instance of 'ExtBaseA' has no 'only_in_b' member; maybe 'only_in_a'?:INFERENCE
no-member:49:0:49:15::Instance of 'Base' has no 'only_in_a' member:INFERENCE
no-member:50:0:50:15::Instance of 'Base' has no 'only_in_b' member:INFERENCE
no-member:55:0:55:15::Instance of 'Base' has no 'only_in_a' member:INFERENCE
no-member:56:0:56:15::Instance of 'Base' has no 'only_in_b' member:INFERENCE
10 changes: 10 additions & 0 deletions tests/functional/n/no/no_member_type_introspection_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Tests for no-member when type(self)() is returned by a method."""
# pylint: disable=missing-class-docstring,missing-function-docstring,too-few-public-methods


# Test for: https://github.com/PyCQA/pylint/issues/7464


class Base:
def return_type(self):
return type(self)()

0 comments on commit 5951048

Please sign in to comment.