Skip to content

Commit

Permalink
Revert #893: Avoid setting a Call as a base for metaclasses from six.…
Browse files Browse the repository at this point in the history
…with_metaclass() (#1622)
  • Loading branch information
jacobtylerwalls authored Jun 23, 2022
1 parent 7db01c1 commit 5f01da9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Release date: TBA

* ``astroid`` now requires Python 3.7.2 to run.

* Avoid setting a Call as a base for classes created using ``six.with_metaclass()``.

Refs PyCQA/pylint#5935

* Fix detection of builtins on ``PyPy`` 3.9.

* Fix ``re`` brain on Python ``3.11``. The flags now come from ``re._compile``.
Expand Down
1 change: 1 addition & 0 deletions astroid/brain/brain_six.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def transform_six_with_metaclass(node):
"""
call = node.bases[0]
node._metaclass = call.args[0]
node.bases = call.args[1:]
return node


Expand Down
18 changes: 17 additions & 1 deletion tests/unittest_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,29 @@ class B(six.with_metaclass(A, C)):
inferred = next(ast_node.infer())
self.assertIsInstance(inferred, nodes.ClassDef)
self.assertEqual(inferred.name, "B")
self.assertIsInstance(inferred.bases[0], nodes.Call)
self.assertIsInstance(inferred.bases[0], nodes.Name)
self.assertEqual(inferred.bases[0].name, "C")
ancestors = tuple(inferred.ancestors())
self.assertIsInstance(ancestors[0], nodes.ClassDef)
self.assertEqual(ancestors[0].name, "C")
self.assertIsInstance(ancestors[1], nodes.ClassDef)
self.assertEqual(ancestors[1].name, "object")

@staticmethod
def test_six_with_metaclass_enum_ancestor() -> None:
code = """
import six
from enum import Enum, EnumMeta
class FooMeta(EnumMeta):
pass
class Foo(six.with_metaclass(FooMeta, Enum)): #@
bar = 1
"""
klass = astroid.extract_node(code)
assert list(klass.ancestors())[-1].name == "Enum"

def test_six_with_metaclass_with_additional_transform(self) -> None:
def transform_class(cls: Any) -> ClassDef:
if cls.name == "A":
Expand Down

0 comments on commit 5f01da9

Please sign in to comment.