From 5d365583ee3720aa5d83590faa6cbcb77f151bae Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 23 Jan 2019 11:58:41 -0800 Subject: [PATCH] A better hack for IndentationError This is fragile -- it just substitutes 'suite' when 'func_body_suite' is found but type comments are off. --- Parser/parser.c | 10 ++++++++-- Parser/parsetok.c | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Parser/parser.c b/Parser/parser.c index a9916d392aab..b082afca27b6 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -12,6 +12,7 @@ #include "node.h" #include "parser.h" #include "errcode.h" +#include "graminit.h" #ifdef Py_DEBUG @@ -260,7 +261,12 @@ PyParser_AddToken(parser_state *ps, int type, char *str, /* Push non-terminal */ int nt = (x >> 8) + NT_OFFSET; int arrow = x & ((1<<7)-1); - dfa *d1 = PyGrammar_FindDFA( + dfa *d1; + if (nt == func_body_suite && !(ps->p_flags & PyCF_TYPE_COMMENTS)) { + D(printf(" [switch func_body_suite to suite]")); + nt = suite; + } + d1 = PyGrammar_FindDFA( ps->p_grammar, nt); if ((err = push(&ps->p_stack, nt, d1, arrow, lineno, col_offset, @@ -268,7 +274,7 @@ PyParser_AddToken(parser_state *ps, int type, char *str, D(printf(" MemError: push\n")); return err; } - D(printf(" Push ...\n")); + D(printf(" Push '%s'\n", d1->d_name)); continue; } diff --git a/Parser/parsetok.c b/Parser/parsetok.c index c543353ecd5c..6fcf91570176 100644 --- a/Parser/parsetok.c +++ b/Parser/parsetok.c @@ -245,6 +245,8 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret, #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD if (*flags & PyPARSE_BARRY_AS_BDFL) ps->p_flags |= CO_FUTURE_BARRY_AS_BDFL; + if (*flags & PyPARSE_TYPE_COMMENTS) + ps->p_flags |= PyCF_TYPE_COMMENTS; #endif for (;;) { -- 2.47.3