summaryrefslogtreecommitdiffstats
path: root/Parser/tokenizer.c
diff options
context:
space:
mode:
authorMichael J. Sullivan <sully@msully.net>2019-05-22 14:54:20 (GMT)
committerIvan Levkivskyi <levkivskyi@gmail.com>2019-05-22 14:54:20 (GMT)
commit933e1509ec6efa8e6ab8c8c7ce02059ce2b6d9b9 (patch)
tree97980dec3873370773b481e2bc1f08f9f1624b9d /Parser/tokenizer.c
parent4c7a46eb3c009c85ddf2eb315d94d804745187d4 (diff)
downloadcpython-933e1509ec6efa8e6ab8c8c7ce02059ce2b6d9b9.zip
cpython-933e1509ec6efa8e6ab8c8c7ce02059ce2b6d9b9.tar.gz
cpython-933e1509ec6efa8e6ab8c8c7ce02059ce2b6d9b9.tar.bz2
bpo-36878: Track extra text added to 'type: ignore' in the AST (GH-13479)
GH-13238 made extra text after a # type: ignore accepted by the parser. This finishes the job and actually plumbs the extra text through the parser and makes it available in the AST.
Diffstat (limited to 'Parser/tokenizer.c')
-rw-r--r--Parser/tokenizer.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index e52d498..9b269af 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -1269,6 +1269,7 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
/* This is a type comment if we matched all of type_comment_prefix. */
if (!*prefix) {
int is_type_ignore = 1;
+ const char *ignore_end = p + 6;
tok_backup(tok, c); /* don't eat the newline or EOF */
type_start = p;
@@ -1276,10 +1277,13 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
/* A TYPE_IGNORE is "type: ignore" followed by the end of the token
* or anything non-alphanumeric. */
is_type_ignore = (
- tok->cur >= p + 6 && memcmp(p, "ignore", 6) == 0
- && !(tok->cur > p + 6 && isalnum(p[6])));
+ tok->cur >= ignore_end && memcmp(p, "ignore", 6) == 0
+ && !(tok->cur > ignore_end && isalnum(p[6])));
if (is_type_ignore) {
+ *p_start = (char *) ignore_end;
+ *p_end = tok->cur;
+
/* If this type ignore is the only thing on the line, consume the newline also. */
if (blankline) {
tok_nextc(tok);