summaryrefslogtreecommitdiff
path: root/astroid/interpreter/scope.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-02-01 11:53:36 +0000
committerClaudiu Popa <pcmanticore@gmail.com>2016-02-13 14:08:58 +0000
commit6d2529632bae545ff7564501cac14316d5ea9204 (patch)
treecfcb11c01f1ddd4806a24469687a1ebc18bd41f4 /astroid/interpreter/scope.py
parent18fa724c04c2393b134d57d4fe4cebe38472bad8 (diff)
downloadastroid-git-6d2529632bae545ff7564501cac14316d5ea9204.tar.gz
Changed the way how parameters are being built
The old way consisted in having the parameter names, their defaults and their annotations separated in different components of the Arguments node. We introduced a new Param node, which holds the name of a parameter, its default value and its annotation. If any of the last two values are missing, then that slot will be filled with a new node kind, Empty, which is used for specifying the lack of something (None could have been used instead, but that means having non-AST nodes in the Arguments node). We're also having support for positional only arguments, for the moment only in raw_building. Close #215
Diffstat (limited to 'astroid/interpreter/scope.py')
-rw-r--r--astroid/interpreter/scope.py21
1 files changed, 12 insertions, 9 deletions
diff --git a/astroid/interpreter/scope.py b/astroid/interpreter/scope.py
index 0d092ce2..47fb3a0c 100644
--- a/astroid/interpreter/scope.py
+++ b/astroid/interpreter/scope.py
@@ -41,20 +41,23 @@ def _scope_by_parent(parent, node):
# in order to decouple the implementation for the normal cases.
+def _node_arguments(node):
+ for arg in itertools.chain(node.positional_and_keyword, node.keyword_only,
+ (node.vararg, ), (node.kwarg, )):
+ if arg and arg.annotation:
+ yield arg
+
+
@_scope_by_parent.register(treeabc.Arguments)
def _scope_by_argument_parent(parent, node):
args = parent
- if node in itertools.chain(args.defaults, args.kw_defaults):
- return args.parent.parent.scope()
- if six.PY3:
- look_for = itertools.chain(
- (args.kwargannotation, ),
- (args.varargannotation, ),
- args.kwonly_annotations,
- args.annotations)
- if node in look_for:
+ for param in itertools.chain(args.positional_and_keyword, args.keyword_only):
+ if param.default == node:
return args.parent.parent.scope()
+ if six.PY3 and node in _node_arguments(args):
+ return args.parent.parent.scope()
+
@_scope_by_parent.register(treeabc.FunctionDef)
def _scope_by_function_parent(parent, node):