summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2014-07-29 11:36:15 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2014-07-29 11:36:15 +0300
commitbf919348a823a573ebbb7c435626172ba21b7c3c (patch)
treef6bee267871fb7b66e49f26a542d549a84e525a6
parent70b05d23a03218cd16bcde339f4ba50dc4a8f27a (diff)
downloadastroid-git-bf919348a823a573ebbb7c435626172ba21b7c3c.tar.gz
Set the parent of vararg and kwarg nodes when inferring them. Closes issue #43.
-rw-r--r--ChangeLog3
-rw-r--r--protocols.py8
-rw-r--r--test/unittest_inference.py20
3 files changed, 29 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index dcc1093a..2fff5b84 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@ Change log for the astroid package (used to be astng)
* Fix a crash occurred when inferring decorator call chain.
Closes issue #42.
+ * Set the parent of vararg and kwarg nodes when inferring them.
+ Closes issue #43.
+
2014-07-25 -- 1.2.0
* Function nodes can detect decorator call chain and see if they are
diff --git a/protocols.py b/protocols.py
index 7ce1faa6..d621ffb6 100644
--- a/protocols.py
+++ b/protocols.py
@@ -231,10 +231,14 @@ def _arguments_infer_argname(self, name, context):
yield self.parent.parent.frame()
return
if name == self.vararg:
- yield const_factory(())
+ vararg = const_factory(())
+ vararg.parent = self
+ yield vararg
return
if name == self.kwarg:
- yield const_factory({})
+ kwarg = const_factory({})
+ kwarg.parent = self
+ yield kwarg
return
# if there is a default value, yield it. And then yield YES to reflect
# we can't guess given argument value
diff --git a/test/unittest_inference.py b/test/unittest_inference.py
index c7036819..7e70ed3b 100644
--- a/test/unittest_inference.py
+++ b/test/unittest_inference.py
@@ -1220,5 +1220,25 @@ empty_list = A().empty_method()
empty_list = astroid['empty_list'].infered()[0]
self.assertIsInstance(empty_list, nodes.List)
+ def test_infer_variable_arguments(self):
+ code = '''
+def test(*args, **kwargs):
+ vararg = args
+ kwarg = kwargs
+ '''
+ astroid = builder.string_build(code, __name__, __file__)
+ func = astroid['test']
+ vararg = func.body[0].value
+ kwarg = func.body[1].value
+
+ kwarg_infered = kwarg.infered()[0]
+ self.assertIsInstance(kwarg_infered, nodes.Dict)
+ self.assertIs(kwarg_infered.parent, func.args)
+
+ vararg_infered = vararg.infered()[0]
+ self.assertIsInstance(vararg_infered, nodes.Tuple)
+ self.assertIs(vararg_infered.parent, func.args)
+
+
if __name__ == '__main__':
unittest_main()