diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2023-03-26 15:01:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-26 15:01:57 +0200 |
commit | 054455afea299c262cdfd4d34c808bc231a10f6e (patch) | |
tree | f1b8417770079137c5da90605415715f3f13aeb7 /astroid | |
parent | edf88c65d794acb5582e1d27589be9fa73b00424 (diff) | |
download | astroid-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 'astroid')
-rw-r--r-- | astroid/brain/brain_six.py | 1 | ||||
-rw-r--r-- | astroid/nodes/scoped_nodes/scoped_nodes.py | 10 |
2 files changed, 9 insertions, 2 deletions
diff --git a/astroid/brain/brain_six.py b/astroid/brain/brain_six.py index a35cfdd6..0eb945d8 100644 --- a/astroid/brain/brain_six.py +++ b/astroid/brain/brain_six.py @@ -219,7 +219,6 @@ def transform_six_with_metaclass(node): """ call = node.bases[0] node._metaclass = call.args[0] - node.bases = call.args[1:] return node diff --git a/astroid/nodes/scoped_nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes/scoped_nodes.py index bec817d7..530d9e6d 100644 --- a/astroid/nodes/scoped_nodes/scoped_nodes.py +++ b/astroid/nodes/scoped_nodes/scoped_nodes.py @@ -1703,7 +1703,15 @@ class FunctionDef(_base_nodes.MultiLineBlockNode, _base_nodes.Statement, Lambda) metaclass = next(caller.args[0].infer(context), None) if isinstance(metaclass, ClassDef): try: - class_bases = [next(arg.infer(context)) for arg in caller.args[1:]] + class_bases = [ + # Find the first non-None inferred base value + next( + b + for b in arg.infer(context=context.clone()) + if not (isinstance(b, Const) and b.value is None) + ) + for arg in caller.args[1:] + ] except StopIteration as e: raise InferenceError(node=caller.args[1:], context=context) from e new_class = ClassDef(name="temporary_class") |