diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2019-06-02 09:29:36 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-06-02 10:01:52 +0200 |
commit | 0441055d1b917781ba838b4796fe82d07ec478e3 (patch) | |
tree | 7a3039dce61f2ca7883cb95a65bc7e3411ef342d /astroid/protocols.py | |
parent | a63f18dfa7e15f8243409bd121011b7c01707582 (diff) | |
download | astroid-git-0441055d1b917781ba838b4796fe82d07ec478e3.tar.gz |
Add inference support to NamedExpr nodes
Diffstat (limited to 'astroid/protocols.py')
-rw-r--r-- | astroid/protocols.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/astroid/protocols.py b/astroid/protocols.py index bf497ff1..b598ec3d 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -572,6 +572,23 @@ def with_assigned_stmts(self, node=None, context=None, assign_path=None): nodes.With.assigned_stmts = with_assigned_stmts +@decorators.raise_if_nothing_inferred +def named_expr_assigned_stmts(self, node, context=None, assign_path=None): + """Infer names and other nodes from an assignment expression""" + if self.target == node: + yield from self.value.infer(context=context) + else: + raise exceptions.InferenceError( + "Cannot infer NamedExpr node {node!r}", + node=self, + assign_path=assign_path, + context=context, + ) + + +nodes.NamedExpr.assigned_stmts = named_expr_assigned_stmts + + @decorators.yes_if_nothing_inferred def starred_assigned_stmts(self, node=None, context=None, assign_path=None): """ |