diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2022-09-07 09:43:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-07 09:43:22 +0200 |
commit | 7c36d112136180420fb78825f3244e02da80174e (patch) | |
tree | 5e3c38be37f98ba422944047eff04e4dcec434f5 /astroid/brain | |
parent | 3f9c9d0f46e00199f1c2f14ed53ef5d2d88b8fc7 (diff) | |
download | astroid-git-7c36d112136180420fb78825f3244e02da80174e.tar.gz |
Fix a crash on ``namedtuples`` that use ``typename`` (#1773)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'astroid/brain')
-rw-r--r-- | astroid/brain/brain_namedtuple_enum.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/astroid/brain/brain_namedtuple_enum.py b/astroid/brain/brain_namedtuple_enum.py index acc20c51..aa2ff3ce 100644 --- a/astroid/brain/brain_namedtuple_enum.py +++ b/astroid/brain/brain_namedtuple_enum.py @@ -538,10 +538,22 @@ def _get_namedtuple_fields(node: nodes.Call) -> str: extract a node from them later on. """ names = [] + container = None try: container = next(node.args[1].infer()) except (InferenceError, StopIteration) as exc: raise UseInferenceDefault from exc + # We pass on IndexError as we'll try to infer 'field_names' from the keywords + except IndexError: + pass + if not container: + for keyword_node in node.keywords: + if keyword_node.arg == "field_names": + try: + container = next(keyword_node.value.infer()) + except (InferenceError, StopIteration) as exc: + raise UseInferenceDefault from exc + break if not isinstance(container, nodes.BaseContainer): raise UseInferenceDefault for elt in container.elts: |