summaryrefslogtreecommitdiff
path: root/tests/unittest_builder.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-11-26 09:17:10 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2019-11-26 09:17:10 +0100
commit2cb6818ad5db25fd0f32a193ab90425e7dfcbee0 (patch)
tree3d8666f65a776dbdd81c61b20b1c6404d09d0582 /tests/unittest_builder.py
parent5cdefb0d278dfe80a662156a942472794df5ca67 (diff)
downloadastroid-git-2cb6818ad5db25fd0f32a193ab90425e7dfcbee0.tar.gz
Retry parsing a module that has invalid type comments
It is possible for a module to use comments that might be interpreted as type comments by the `ast` library. We do not want to completely crash on those invalid type comments. Close #708
Diffstat (limited to 'tests/unittest_builder.py')
-rw-r--r--tests/unittest_builder.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/unittest_builder.py b/tests/unittest_builder.py
index 0f1a470f..75557761 100644
--- a/tests/unittest_builder.py
+++ b/tests/unittest_builder.py
@@ -692,5 +692,30 @@ def test_module_build_dunder_file():
assert module.path[0] == collections.__file__
+def test_parse_module_with_invalid_type_comments_does_not_crash():
+ node = builder.parse(
+ """
+ # op {
+ # name: "AssignAddVariableOp"
+ # input_arg {
+ # name: "resource"
+ # type: DT_RESOURCE
+ # }
+ # input_arg {
+ # name: "value"
+ # type_attr: "dtype"
+ # }
+ # attr {
+ # name: "dtype"
+ # type: "type"
+ # }
+ # is_stateful: true
+ # }
+ a, b = 2
+ """
+ )
+ assert isinstance(node, nodes.Module)
+
+
if __name__ == "__main__":
unittest.main()