Skip to content

Commit

Permalink
Add regression tests of properties on derived classes
Browse files Browse the repository at this point in the history
  • Loading branch information
nelfin committed May 14, 2021
1 parent 440d4d6 commit 97fd3a3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# pylint: disable=missing-docstring,too-few-public-methods

class Meta(type):
@property
def values(cls):
return ['foo', 'bar']


class Parent(metaclass=Meta):
pass


assert 'foo' in Parent.values # no warning
for value in Parent.values: # no warning
print(value)


class Child(Parent):
pass


assert 'foo' in Child.values # false-positive: unsupported-membership-test
for value in Child.values: # false-positive: not-an-iterable
print(value)


class Meta2(type):
def a_method(cls): # pylint: disable=no-self-use
return [123]


class Parent2(metaclass=Meta2):
@property
def a_method(self):
return "actually a property"


class Child2(Parent2):
pass


assert 123 in Child2.a_method # [unsupported-membership-test]
for value in Child2.a_method: # [not-an-iterable]
print(value)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
unsupported-membership-test:42:14::Value 'Child2.a_method' doesn't support membership test
not-an-iterable:43:13::Non-iterable value Child2.a_method is used in an iterating context

0 comments on commit 97fd3a3

Please sign in to comment.