-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supporting type_comments=True #95
Comments
IMO for alpha6 we can just make these flags use the old parser. But we do need to do that (else mypy won't be able to work with alpha 6 unless you use -X oldparser). |
Done in 0bd4bc3, |
Okay, I am looking into how to do this post-alpha6. (FWIW I've fixed mypy to work with the 3.9 but you need to use master from https://github.com/python/mypy/.) There are actually several separate things to implement:
|
This implements full support for # type: <type> comments, # type: ignore <stuff> comments, and the func_type parsing mode for ast.parse() and compile(). Closes we-like-parsers#95. (For now, you need to use the master branch of mypy, since another issue unique to 3.9 had to be fixed there, and there's no mypy release yet.) The only thing missing is `feature_version=N`, which is being tracked in we-like-parsers#124.
The
ast.parse()
function has two barely documented features,type_comments=
andfeature_version=
, which modify the tokenizer and parser for the benefit of (primarily) mypy.type_comments=True
changes the tokenizer to returnTYPE_COMMENT
tokens when it detects a type comment (a comment starting with 'type:'), and the old Grammar file has[TYPE_COMMENT]
sprinkled throughout to support these.In addition,[moved to #124]feature_version=(3, N)
enables a few changes in the tokenizer and ast.c to support older Python versions (mostly related to the three different stages of support forasync
andawait
keywords).We'll have to support these. I think it won't be very difficult since most of the logic is part of the tokenizer, but we'll have to check ast.c for other tests for
feature_version
. Note that these flags are passed in different forms tocompile()
, which has the actual support, but undocumented. See the source of ast.py.The text was updated successfully, but these errors were encountered: