classification
Title: ast.parse with type_comments=True should allow extra text after # type: ignore
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, levkivskyi, miss-islington, msullivan
Priority: normal Keywords: patch

Created on 2019-05-10 20:40 by msullivan, last changed 2019-05-22 21:28 by msullivan. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 13238 merged msullivan, 2019-05-10 20:50
PR 13479 merged msullivan, 2019-05-21 23:42
PR 13504 merged msullivan, 2019-05-22 19:11
Messages (9)
msg342130 - (view) Author: Michael J. Sullivan (msullivan) * Date: 2019-05-10 20:40
Per discussion during the typing summit at PyCon, it would be a good idea to allow extra information to be included in `# type: ignore` comments, in order to allow behavior such as suppressing individual errors (for example, with syntax like `# type: ignore[E1000]`, to suppress error 1000).

My proposal, then, is to generalize the definition of type: ignore comments to be `# type: ignore followed by a non-alphanumeric character. Then `# type: ignore[E1000]` and `# type: ignore E1000` would be valid type ignore comments while `# type: ignoreE1000` would not be.

Now that ast.parse can parse type_comments, this needs to make it into 3.8, basically, if we want to do this and be able to use the ast type_comment feature.

Ideally, the text of the type ignore would be actually included in the produced AST. As a bare minimum first step, we need to recognize type ignores with extra information and report them (and, critically, not detect them as regular type comments and produce errors when they appear in unexpected places).

I'll put up a PR to do the second part shortly.
msg342144 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2019-05-11 01:03
I like the idea of separate smaller PRs, the first one looks good.
msg342213 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2019-05-11 18:17
New changeset d8320ecb86da8df7c13d8bf8582507f736aa2924 by Ivan Levkivskyi (Michael J. Sullivan) in branch 'master':
bpo-36878: Allow extra text after `# type: ignore` comments (GH-13238)
https://github.com/python/cpython/commit/d8320ecb86da8df7c13d8bf8582507f736aa2924
msg343130 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2019-05-21 23:45
How many more PRs do you plan? Or is this it?
msg343198 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2019-05-22 14:54
New changeset 933e1509ec6efa8e6ab8c8c7ce02059ce2b6d9b9 by Ivan Levkivskyi (Michael J. Sullivan) in branch 'master':
bpo-36878: Track extra text added to 'type: ignore' in the AST (GH-13479)
https://github.com/python/cpython/commit/933e1509ec6efa8e6ab8c8c7ce02059ce2b6d9b9
msg343205 - (view) Author: Michael J. Sullivan (msullivan) * Date: 2019-05-22 15:50
I think there will be one more PR to disallow non-ASCII characters immediately after a `# type: ignore`, but otherwise I think this is done
msg343236 - (view) Author: miss-islington (miss-islington) Date: 2019-05-22 20:43
New changeset d8a82e2897b735e2b7e9e086f1d709365a2ad72c by Miss Islington (bot) (Michael J. Sullivan) in branch 'master':
bpo-36878: Only allow text after `# type: ignore` if first character ASCII (GH-13504)
https://github.com/python/cpython/commit/d8a82e2897b735e2b7e9e086f1d709365a2ad72c
msg343237 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2019-05-22 21:08
Thanks!
msg343240 - (view) Author: Michael J. Sullivan (msullivan) * Date: 2019-05-22 21:28
I think this is done!
History
Date User Action Args
2019-05-22 21:28:13msullivansetmessages: + msg343240
2019-05-22 21:08:33gvanrossumsetstatus: open -> closed
resolution: fixed
messages: + msg343237

stage: patch review -> resolved
2019-05-22 20:43:42miss-islingtonsetnosy: + miss-islington
messages: + msg343236
2019-05-22 19:11:59msullivansetpull_requests: + pull_request13419
2019-05-22 15:50:14msullivansetmessages: + msg343205
2019-05-22 14:54:33levkivskyisetmessages: + msg343198
2019-05-21 23:45:05gvanrossumsetmessages: + msg343130
2019-05-21 23:42:59msullivansetpull_requests: + pull_request13391
2019-05-11 18:17:27levkivskyisetmessages: + msg342213
2019-05-11 01:03:29levkivskyisetmessages: + msg342144
2019-05-10 20:50:39msullivansetkeywords: + patch
stage: patch review
pull_requests: + pull_request13148
2019-05-10 20:40:16msullivancreate