Skip to content

Commit 3d19dbb

Browse files
committed
Support passing type ignores to Module object
1 parent 72e4f4d commit 3d19dbb

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Python/ast.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ PyAST_FromNodeObject(const node *n, PyCompilerFlags *flags,
751751
{
752752
int i, j, k, num;
753753
asdl_seq *stmts = NULL;
754+
asdl_seq *type_ignores = NULL;
754755
stmt_ty s;
755756
node *ch;
756757
struct compiling c;
@@ -793,7 +794,23 @@ PyAST_FromNodeObject(const node *n, PyCompilerFlags *flags,
793794
}
794795
}
795796
}
796-
res = Module(stmts, NULL, arena);
797+
798+
/* Type ignores are stored under the ENDMARKER in file_input. */
799+
ch = CHILD(n, NCH(n) - 1);
800+
REQ(ch, ENDMARKER);
801+
num = NCH(ch);
802+
type_ignores = _Py_asdl_seq_new(num, arena);
803+
if (!type_ignores)
804+
goto out;
805+
806+
for (i = 0; i < num; i++) {
807+
type_ignore_ty ti = TypeIgnore(LINENO(CHILD(ch, i)), arena);
808+
if (!ti)
809+
goto out;
810+
asdl_seq_SET(type_ignores, i, ti);
811+
}
812+
813+
res = Module(stmts, type_ignores, arena);
797814
break;
798815
case eval_input: {
799816
expr_ty testlist_ast;

0 commit comments

Comments
 (0)