return await bar()
"""
+redundantdef = """\
+def foo(): # type: () -> int
+ # type: () -> str
+ return ''
+"""
+
forstmt = """\
for a in []: # type: int
pass
"""
-
withstmt = """\
with context() as a: # type: int
pass
self.assertEqual(tree.body[0].type_comment, None)
self.assertEqual(tree.body[1].type_comment, None)
+ def test_redundantdef(self):
+ with self.assertRaisesRegex(SyntaxError, "^Cannot have two type comments on def"):
+ tree = self.parse(redundantdef)
+
def test_forstmt(self):
tree = self.parse(forstmt)
self.assertEqual(tree.body[0].type_comment, "int")
return NULL;
get_last_end_pos(body, &end_lineno, &end_col_offset);
- if (!type_comment && NCH(CHILD(n, name_i + 3)) > 1) {
- /* If the function doesn't have a type comment on the same line, check
- * if the suite has a type comment in it. */
+ if (NCH(CHILD(n, name_i + 3)) > 1) {
+ /* Check if the suite has a type comment in it. */
tc = CHILD(CHILD(n, name_i + 3), 1);
- if (TYPE(tc) == TYPE_COMMENT)
+ if (TYPE(tc) == TYPE_COMMENT) {
+ if (type_comment != NULL) {
+ ast_error(c, n, "Cannot have two type comments on def");
+ return NULL;
+ }
type_comment = NEW_TYPE_COMMENT(tc);
+ }
}
if (is_async)