summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtsiom Kaval <lezeroq@gmail.com>2021-05-29 13:06:37 +0300
committerGitHub <noreply@github.com>2021-05-29 12:06:37 +0200
commit8d7019531868eab63f72eefc1b9ee5e59b6d1299 (patch)
tree61f9aa8bf55f686805cc79c4a46e8f133276c096
parent88cee6f2f6535afeab49e42c9a4b01ea64b0810a (diff)
downloadastroid-git-8d7019531868eab63f72eefc1b9ee5e59b6d1299.tar.gz
Fix six.with_metaclass transformation so it doesn't break user defined transformations (#975)
* Fix six.with_metaclass transformation so it doesn't break user defined transformations
-rw-r--r--ChangeLog2
-rw-r--r--astroid/brain/brain_six.py1
-rw-r--r--tests/unittest_brain.py22
3 files changed, 25 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 88ce55df..0da3c997 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,8 @@ What's New in astroid 2.5.7?
============================
Release Date: TBA
+* Fix six.with_metaclass transformation so it doesn't break user defined transformations.
+
* Fix detection of relative imports.
Closes #930
Closes PyCQA/pylint#4186
diff --git a/astroid/brain/brain_six.py b/astroid/brain/brain_six.py
index aa22701d..91d3da16 100644
--- a/astroid/brain/brain_six.py
+++ b/astroid/brain/brain_six.py
@@ -225,6 +225,7 @@ def transform_six_with_metaclass(node):
"""
call = node.bases[0]
node._metaclass = call.args[0]
+ return node
register_module_extender(MANAGER, "six", six_moves_transform)
diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py
index 26fad2e3..a463fd3e 100644
--- a/tests/unittest_brain.py
+++ b/tests/unittest_brain.py
@@ -495,6 +495,28 @@ class SixBrainTest(unittest.TestCase):
self.assertIsInstance(ancestors[1], nodes.ClassDef)
self.assertEqual(ancestors[1].name, "object")
+ def test_six_with_metaclass_with_additional_transform(self):
+ def transform_class(cls):
+ if cls.name == "A":
+ cls._test_transform = 314
+ return cls
+
+ MANAGER.register_transform(nodes.ClassDef, transform_class)
+ try:
+ ast_node = builder.extract_node(
+ """
+ import six
+ class A(six.with_metaclass(type, object)):
+ pass
+
+ A #@
+ """
+ )
+ inferred = next(ast_node.infer())
+ assert getattr(inferred, "_test_transform", None) == 314
+ finally:
+ MANAGER.unregister_transform(nodes.ClassDef, transform_class)
+
@unittest.skipUnless(
HAS_MULTIPROCESSING,