summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2021-11-21 20:42:32 +0100
committerGitHub <noreply@github.com>2021-11-21 20:42:32 +0100
commit2904ae04a2cf6bc341873e6b902883a777452953 (patch)
tree9eb7dfc8382206a3061e0749ee6d14091f499454
parent079805b0f9d0324d1731595c0c6f8f36e5a999f4 (diff)
downloadpylint-git-2904ae04a2cf6bc341873e6b902883a777452953.tar.gz
Add tests `inherit-non-class` with subscriptable class (#5354)
* Add tests inherit-non-class with subscriptable class
-rw-r--r--ChangeLog2
-rw-r--r--tests/functional/i/inherit_non_class.py23
-rw-r--r--tests/functional/i/inherit_non_class.txt2
3 files changed, 27 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index b682defa6..10adc3379 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -195,6 +195,8 @@ Release date: TBA
Partially closes #5321
+* Inheriting from a class that implements ``__class_getitem__`` no longer raises ``inherit-non-class``.
+
What's New in Pylint 2.11.2?
============================
diff --git a/tests/functional/i/inherit_non_class.py b/tests/functional/i/inherit_non_class.py
index bbee6bd9a..7454744d9 100644
--- a/tests/functional/i/inherit_non_class.py
+++ b/tests/functional/i/inherit_non_class.py
@@ -79,3 +79,26 @@ class NotInheritableSlice(slice): # [inherit-non-class]
class NotInheritableMemoryView(memoryview): # [inherit-non-class]
pass
+
+
+# Subscription of parent class that implements __class_getitem__
+# and returns cls should be allowed.
+class ParentGood:
+ def __class_getitem__(cls, item): # pylint: disable=unused-argument
+ return cls
+
+class ParentBad:
+ def __class_getitem__(cls, item): # pylint: disable=unused-argument
+ return 42
+
+# pylint: disable-next=fixme
+# TODO This should emit 'unsubscriptable-object' for Python 3.6
+class Child1(ParentGood[int]):
+ pass
+
+class Child2(ParentBad[int]): # [inherit-non-class]
+ pass
+
+# Classes that don't implement '__class_getitem__' are marked as unsubscriptable
+class Child3(Empty[int]): # [unsubscriptable-object]
+ pass
diff --git a/tests/functional/i/inherit_non_class.txt b/tests/functional/i/inherit_non_class.txt
index 9252c2fbf..e8a9b0b6f 100644
--- a/tests/functional/i/inherit_non_class.txt
+++ b/tests/functional/i/inherit_non_class.txt
@@ -7,3 +7,5 @@ inherit-non-class:68:0:NotInheritableBool:Inheriting 'bool', which is not a clas
inherit-non-class:72:0:NotInheritableRange:Inheriting 'range', which is not a class.
inherit-non-class:76:0:NotInheritableSlice:Inheriting 'slice', which is not a class.
inherit-non-class:80:0:NotInheritableMemoryView:Inheriting 'memoryview', which is not a class.
+inherit-non-class:99:0:Child2:Inheriting 'ParentBad[int]', which is not a class.:HIGH
+unsubscriptable-object:103:13:Child3:Value 'Empty' is unsubscriptable:HIGH