summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-07-27 01:51:15 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2016-07-27 02:01:21 +0300
commit8f1d6bba30aeae80770df4a85d8d497a2d73a39d (patch)
tree6042b6c6b92ae02c0d01eb0f977897ced147f045
parent106661a53742d611e1833116171e3d58a2141731 (diff)
downloadastroid-git-8f1d6bba30aeae80770df4a85d8d497a2d73a39d.tar.gz
Add `returns` into the proper order in FunctionDef._astroid_fields
The order is important, since it determines the last child, which in turn determines the last line number of a scoped node.
-rw-r--r--ChangeLog8
-rw-r--r--astroid/scoped_nodes.py2
-rw-r--r--astroid/tests/unittest_scoped_nodes.py12
3 files changed, 21 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index e46a8fa6..60095658 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,14 @@
Change log for the astroid package (used to be astng)
=====================================================
+2016-07-27 -- 1.4.8
+
+ * Add `returns` into the proper order in FunctionDef._astroid_fields
+
+ The order is important, since it determines the last child,
+ which in turn determines the last line number of a scoped node.
+
+
2016-07-07 -- 1.4.7
* Stop saving assignment locals in ExceptHandlers, when the context is a store.
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py
index 2a23f0b6..d78d1510 100644
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -708,7 +708,7 @@ class Lambda(mixins.FilterStmtsMixin, LocalsDictNodeNG):
class FunctionDef(bases.Statement, Lambda):
if six.PY3:
- _astroid_fields = ('decorators', 'args', 'body', 'returns')
+ _astroid_fields = ('decorators', 'args', 'returns', 'body')
returns = None
else:
_astroid_fields = ('decorators', 'args', 'body')
diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py
index 0019ee08..a15c923a 100644
--- a/astroid/tests/unittest_scoped_nodes.py
+++ b/astroid/tests/unittest_scoped_nodes.py
@@ -576,6 +576,18 @@ class FunctionNodeTest(ModuleLoader, unittest.TestCase):
self.assertIsInstance(inferred, nodes.Const)
self.assertEqual(inferred.value, 42)
+ @test_utils.require_version(minver='3.0')
+ def test_return_annotation_is_not_the_last(self):
+ func = builder.parse('''
+ def test() -> bytes:
+ pass
+ pass
+ return
+ ''').body[0]
+ last_child = func.last_child()
+ self.assertIsInstance(last_child, nodes.Return)
+ self.assertEqual(func.tolineno, 5)
+
class ClassNodeTest(ModuleLoader, unittest.TestCase):