Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/test/test_type_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def check_both_ways(source):
check_both_ways("try: # type: int\n pass\nfinally:\n pass\n")
check_both_ways("try:\n pass\nfinally: # type: int\n pass\n")
check_both_ways("pass # type: ignorewhatever\n")
check_both_ways("pass # type: ignoreé\n")

def test_func_type_input(self):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Only accept text after `# type: ignore` if the first character is ASCII.
This is to disallow things like `# type: ignoreé`.
5 changes: 3 additions & 2 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1275,10 +1275,11 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
type_start = p;

/* A TYPE_IGNORE is "type: ignore" followed by the end of the token
* or anything non-alphanumeric. */
* or anything ASCII and non-alphanumeric. */
is_type_ignore = (
tok->cur >= ignore_end && memcmp(p, "ignore", 6) == 0
&& !(tok->cur > ignore_end && isalnum(p[6])));
&& !(tok->cur > ignore_end
&& ((unsigned char)ignore_end[0] >= 128 || Py_ISALNUM(ignore_end[0]))));

if (is_type_ignore) {
*p_start = (char *) ignore_end;
Expand Down