-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed the way how parameters are being built #314
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
|
||
from astroid import nodes | ||
from astroid.tree.node_classes import Assign, Expr, YieldFrom, Name, Const | ||
from astroid import raw_building | ||
from astroid.builder import AstroidBuilder | ||
from astroid.tree.scoped_nodes import ClassDef, FunctionDef | ||
from astroid.test_utils import require_version, extract_node | ||
|
@@ -187,31 +188,31 @@ def test(a: int, b: str, c: None, d, e, | |
pass | ||
""")) | ||
func = astroid['test'] | ||
self.assertIsInstance(func.args.varargannotation, Name) | ||
self.assertEqual(func.args.varargannotation.name, 'float') | ||
self.assertIsInstance(func.args.kwargannotation, Name) | ||
self.assertEqual(func.args.kwargannotation.name, 'int') | ||
self.assertIsInstance(func.args.vararg.annotation, Name) | ||
self.assertEqual(func.args.vararg.annotation.name, 'float') | ||
self.assertIsInstance(func.args.kwarg.annotation, Name) | ||
self.assertEqual(func.args.kwarg.annotation.name, 'int') | ||
self.assertIsInstance(func.returns, Name) | ||
self.assertEqual(func.returns.name, 'int') | ||
arguments = func.args | ||
self.assertIsInstance(arguments.annotations[0], Name) | ||
self.assertEqual(arguments.annotations[0].name, 'int') | ||
self.assertIsInstance(arguments.annotations[1], Name) | ||
self.assertEqual(arguments.annotations[1].name, 'str') | ||
self.assertIsInstance(arguments.annotations[2], Const) | ||
self.assertIsNone(arguments.annotations[2].value) | ||
self.assertIsNone(arguments.annotations[3]) | ||
self.assertIsNone(arguments.annotations[4]) | ||
self.assertIsInstance(arguments.args[0].annotation, Name) | ||
self.assertEqual(arguments.args[0].annotation.name, 'int') | ||
self.assertIsInstance(arguments.args[1].annotation, Name) | ||
self.assertEqual(arguments.args[1].annotation.name, 'str') | ||
self.assertIsInstance(arguments.args[2].annotation, Const) | ||
self.assertIsNone(arguments.args[2].annotation.value) | ||
self.assertIs(arguments.args[3].annotation, nodes.Empty) | ||
self.assertIs(arguments.args[4].annotation, nodes.Empty) | ||
|
||
astroid = self.builder.string_build(dedent(""" | ||
def test(a: int=1, b: str=2): | ||
pass | ||
""")) | ||
func = astroid['test'] | ||
self.assertIsInstance(func.args.annotations[0], Name) | ||
self.assertEqual(func.args.annotations[0].name, 'int') | ||
self.assertIsInstance(func.args.annotations[1], Name) | ||
self.assertEqual(func.args.annotations[1].name, 'str') | ||
self.assertIsInstance(func.args.args[0].annotation, Name) | ||
self.assertEqual(func.args.args[0].annotation.name, 'int') | ||
self.assertIsInstance(func.args.args[1].annotation, Name) | ||
self.assertEqual(func.args.args[1].annotation.name, 'str') | ||
self.assertIsNone(func.returns) | ||
|
||
@require_version('3.0') | ||
|
@@ -249,6 +250,13 @@ def test_unpacking_in_dict_getitem(self): | |
self.assertIsInstance(value, nodes.Const) | ||
self.assertEqual(value.value, expected) | ||
|
||
@require_version('3.4') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this test only run on 3.4? Shouldn't it at least run on 3.5 as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the minimum. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, my mistake. That works then. |
||
def test_positional_only_parameters(self): | ||
ast = raw_building.ast_from_object(issubclass) | ||
self.assertEqual(len(ast.args.positional_only), 2) | ||
for name, arg in zip(('cls', 'class_or_tuple'), ast.args.positional_only): | ||
self.assertEqual(arg.name, name) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment could be expanded to clarify what this code is doing. (I'm not clear on its purpose.)