mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
bpo-36878: Allow extra text after # type: ignore comments (GH-13238)
In the parser, when using the type_comments=True option, recognize a TYPE_IGNORE as anything containing `# type: ignore` followed by a non-alphanumeric character. This is to allow ignores such as `# type: ignore[E1000]`.
This commit is contained in:
parent
6236c9823e
commit
d8320ecb86
3 changed files with 17 additions and 9 deletions
|
|
@ -1272,14 +1272,11 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
|
|||
|
||||
type_start = p;
|
||||
|
||||
is_type_ignore = tok->cur >= p + 6 && memcmp(p, "ignore", 6) == 0;
|
||||
p += 6;
|
||||
while (is_type_ignore && p < tok->cur) {
|
||||
if (*p == '#')
|
||||
break;
|
||||
is_type_ignore = is_type_ignore && (*p == ' ' || *p == '\t');
|
||||
p++;
|
||||
}
|
||||
/* 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])));
|
||||
|
||||
if (is_type_ignore) {
|
||||
/* If this type ignore is the only thing on the line, consume the newline also. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue