diff options
author | Dan Albert <danalbert@google.com> | 2021-11-18 15:29:53 -0800 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2021-11-18 15:29:53 -0800 |
commit | 612950b6eae36a543f4645d743f5fd02839c9788 (patch) | |
tree | 3031e603522c7cb51097774097abf2ed3dea119a /tests/functional/i/inherit_non_class.py | |
parent | 3c1d8f114801a00b92ab062ceef2244d502bb7ae (diff) | |
parent | d98e6e8adcdc5ebcd9c863f630e748cdba639b0a (diff) | |
download | pylint-612950b6eae36a543f4645d743f5fd02839c9788.tar.gz |
Merge upstream tag v2.11.1.
Test: None
Bug: http://b/206656351
Change-Id: I7831112fa3014bf7998432f9e1ac96be18fca60c
Diffstat (limited to 'tests/functional/i/inherit_non_class.py')
-rw-r--r-- | tests/functional/i/inherit_non_class.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/functional/i/inherit_non_class.py b/tests/functional/i/inherit_non_class.py new file mode 100644 index 000000000..bbee6bd9a --- /dev/null +++ b/tests/functional/i/inherit_non_class.py @@ -0,0 +1,81 @@ +"""Test that inheriting from something which is not
+a class emits a warning. """
+
+# pylint: disable=no-init, import-error, invalid-name, using-constant-test, useless-object-inheritance
+# pylint: disable=missing-docstring, too-few-public-methods
+
+from missing import Missing
+
+if 1:
+ Ambiguous = None
+else:
+ Ambiguous = int
+
+class Empty(object):
+ """ Empty class. """
+
+def return_class():
+ """ Return a class. """
+ return Good3
+
+class Bad(1): # [inherit-non-class]
+ """ Can't inherit from instance. """
+
+class Bad1(lambda abc: 42): # [inherit-non-class]
+ """ Can't inherit from lambda. """
+
+class Bad2(object()): # [inherit-non-class]
+ """ Can't inherit from an instance of object. """
+
+class Bad3(return_class): # [inherit-non-class]
+ """ Can't inherit from function. """
+
+class Bad4(Empty()): # [inherit-non-class]
+ """ Can't inherit from instance. """
+
+class Good(object):
+ pass
+
+class Good1(int):
+ pass
+
+class Good2(type):
+ pass
+
+class Good3(type(int)):
+ pass
+
+class Good4(return_class()):
+ pass
+
+class Good5(Good4, int, object):
+ pass
+
+class Good6(Ambiguous):
+ """ Inherits from something ambiguous.
+
+ This could emit a warning when we will have
+ flow detection.
+ """
+
+class Unknown(Missing):
+ pass
+
+class Unknown1(Good5 if True else Bad1):
+ pass
+
+
+class NotInheritableBool(bool): # [inherit-non-class]
+ pass
+
+
+class NotInheritableRange(range): # [inherit-non-class]
+ pass
+
+
+class NotInheritableSlice(slice): # [inherit-non-class]
+ pass
+
+
+class NotInheritableMemoryView(memoryview): # [inherit-non-class]
+ pass
|