diff options
| author | hippo91 <guillaume.peillex@gmail.com> | 2020-11-22 15:29:20 +0100 |
|---|---|---|
| committer | hippo91 <guillaume.peillex@gmail.com> | 2020-11-22 15:29:20 +0100 |
| commit | 80d2f63afdb652625e97f6fe10221f27e3a6af38 (patch) | |
| tree | 894e2446473f1960b2d0b80e4b14ad4b24b430ab /astroid | |
| parent | 6b11429e09f72b4dcde1cf77d54c3dcad1faac6b (diff) | |
| download | astroid-git-80d2f63afdb652625e97f6fe10221f27e3a6af38.tar.gz | |
Takes into account the fact that in python3.9 NamedTuple in typing module is no more a class but a function.
Diffstat (limited to 'astroid')
| -rw-r--r-- | astroid/brain/brain_namedtuple_enum.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/astroid/brain/brain_namedtuple_enum.py b/astroid/brain/brain_namedtuple_enum.py index c0aa1c2b..ae1f9900 100644 --- a/astroid/brain/brain_namedtuple_enum.py +++ b/astroid/brain/brain_namedtuple_enum.py @@ -399,6 +399,21 @@ def infer_typing_namedtuple_class(class_node, context=None): return iter((generated_class_node,)) +def infer_typing_namedtuple_function(node, context=None): + """ + Starting with python3.9, NamedTuple is a function of the typing module. + The class NamedTuple is build dynamically through a call to `type` during + initialization of the `_NamedTuple` variable. + """ + klass = extract_node( + """ + from typing import _NamedTuple + _NamedTuple + """ + ) + return klass.infer(context) + + def infer_typing_namedtuple(node, context=None): """Infer a typing.NamedTuple(...) call.""" # This is essentially a namedtuple with different arguments @@ -451,5 +466,9 @@ MANAGER.register_transform( nodes.ClassDef, inference_tip(infer_typing_namedtuple_class), _has_namedtuple_base ) MANAGER.register_transform( + nodes.FunctionDef, inference_tip(infer_typing_namedtuple_function), + lambda node: node.name == "NamedTuple" and node.parent.name == "typing" +) +MANAGER.register_transform( nodes.Call, inference_tip(infer_typing_namedtuple), _looks_like_typing_namedtuple ) |
