summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2023-03-26 15:01:57 +0200
committerGitHub <noreply@github.com>2023-03-26 15:01:57 +0200
commit054455afea299c262cdfd4d34c808bc231a10f6e (patch)
treef1b8417770079137c5da90605415715f3f13aeb7 /tests
parentedf88c65d794acb5582e1d27589be9fa73b00424 (diff)
downloadastroid-git-054455afea299c262cdfd4d34c808bc231a10f6e.tar.gz
Restore setting a Call as a base for classes using `six.with_metaclass` (#2049) (#2067)
Harden support for using enums as metaclasses. Fixes the crash in PyCQA/pylint#5935 by adopting the check for not-none bases as in ClassDef._inferred_bases without recausing the false positive reported in PyCQA/pylint#7506, which requires correct bases. (cherry picked from commit b5ebf994a1c6039fa8ca4706889e007700cdf41a) Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/brain/test_six.py5
-rw-r--r--tests/test_scoped_nodes.py14
2 files changed, 16 insertions, 3 deletions
diff --git a/tests/brain/test_six.py b/tests/brain/test_six.py
index 1ff184d3..c9dac562 100644
--- a/tests/brain/test_six.py
+++ b/tests/brain/test_six.py
@@ -110,8 +110,7 @@ class SixBrainTest(unittest.TestCase):
inferred = next(ast_node.infer())
self.assertIsInstance(inferred, nodes.ClassDef)
self.assertEqual(inferred.name, "B")
- self.assertIsInstance(inferred.bases[0], nodes.Name)
- self.assertEqual(inferred.bases[0].name, "C")
+ self.assertIsInstance(inferred.bases[0], nodes.Call)
ancestors = tuple(inferred.ancestors())
self.assertIsInstance(ancestors[0], nodes.ClassDef)
self.assertEqual(ancestors[0].name, "C")
@@ -131,7 +130,7 @@ class SixBrainTest(unittest.TestCase):
bar = 1
"""
klass = astroid.extract_node(code)
- assert list(klass.ancestors())[-1].name == "Enum"
+ assert next(klass.ancestors()).name == "Enum"
def test_six_with_metaclass_with_additional_transform(self) -> None:
def transform_class(cls: Any) -> ClassDef:
diff --git a/tests/test_scoped_nodes.py b/tests/test_scoped_nodes.py
index a69983c6..2722c56f 100644
--- a/tests/test_scoped_nodes.py
+++ b/tests/test_scoped_nodes.py
@@ -1403,6 +1403,20 @@ class ClassNodeTest(ModuleLoader, unittest.TestCase):
self.assertEqual(["object"], [base.name for base in klass.ancestors()])
self.assertEqual("type", klass.metaclass().name)
+ @unittest.skipUnless(HAS_SIX, "These tests require the six library")
+ def test_metaclass_generator_hack_enum_base(self):
+ """Regression test for https://github.com/PyCQA/pylint/issues/5935"""
+ klass = builder.extract_node(
+ """
+ import six
+ from enum import Enum, EnumMeta
+
+ class PetEnumPy2Metaclass(six.with_metaclass(EnumMeta, Enum)): #@
+ DOG = "dog"
+ """
+ )
+ self.assertEqual(list(klass.local_attr_ancestors("DOG")), [])
+
def test_add_metaclass(self) -> None:
klass = builder.extract_node(
"""