summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorhippo91 <guillaume.peillex@gmail.com>2021-01-23 15:09:53 +0100
committerGitHub <noreply@github.com>2021-01-23 15:09:53 +0100
commit7c7848b7670e57517eb2b42ee605d18b4259248f (patch)
tree9904aa26dbef6726e753d94e2e777629117fc811 /tests
parent869b851169150de2d9208741504d267a43a190ac (diff)
parentded22ec02678d2bb35684093d307cca4efcf5c5e (diff)
downloadastroid-git-7c7848b7670e57517eb2b42ee605d18b4259248f.tar.gz
Merge pull request #883 from hippo91/bug_pylint_4001
Bug pylint 4001
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest_brain.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py
index 4717ab76..e6ff6928 100644
--- a/tests/unittest_brain.py
+++ b/tests/unittest_brain.py
@@ -937,6 +937,42 @@ class IOBrainTest(unittest.TestCase):
self.assertEqual(raw.name, "FileIO")
+@test_utils.require_version("3.9")
+class TypeBrain(unittest.TestCase):
+ def test_type_subscript(self):
+ """
+ Check that type object has the __class_getitem__ method
+ when it is used as a subscript
+ """
+ src = builder.extract_node(
+ """
+ a: type[int] = int
+ """
+ )
+ val_inf = src.annotation.value.inferred()[0]
+ self.assertIsInstance(val_inf, astroid.ClassDef)
+ self.assertEqual(val_inf.name, "type")
+ meth_inf = val_inf.getattr("__class_getitem__")[0]
+ self.assertIsInstance(meth_inf, astroid.FunctionDef)
+
+ def test_invalid_type_subscript(self):
+ """
+ Check that a type (str for example) that inherits
+ from type does not have __class_getitem__ method even
+ when it is used as a subscript
+ """
+ src = builder.extract_node(
+ """
+ a: str[int] = "abc"
+ """
+ )
+ val_inf = src.annotation.value.inferred()[0]
+ self.assertIsInstance(val_inf, astroid.ClassDef)
+ self.assertEqual(val_inf.name, "str")
+ with self.assertRaises(astroid.exceptions.AttributeInferenceError):
+ meth_inf = val_inf.getattr("__class_getitem__")[0]
+
+
@test_utils.require_version("3.6")
class TypingBrain(unittest.TestCase):
def test_namedtuple_base(self):