-
Notifications
You must be signed in to change notification settings - Fork 237
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
Should a misplaced # type:
comment be an error?
#210
Comments
There's a special case that I'd like to discuss too: what if the misplaced def foobar():
# We can't turn on this type comment yet
# type: () -> List[int]
return [] |
I think misplaced I don't think the special case should be treated any differently, because I'd expect the typical case to look like this instead: def foobar():
# Some comment describing foobar or the type of foobar
# type: () -> List[int]
return [] In this case, we'd want to throw an error rather than be silent. Also, type comments are now (statically) semantically meaningful, so it doesn't feel too weird to me that they should have to be commented when used in a comment context, e.g.: def foobar():
# We can't turn on this type comment yet
# # type: () -> List[int]
return [] There's already precedent for double-comments like this: x = 1 # type: int # some comment about the type In my mind, the existence of this construct furthers the feel of type comments as a distinct syntactic construct from normal comments (at least where PEP 484 type checkers are concerned). |
My worry is mainly about things that look like type comments but aren't
meant to be, and which occur in portions of the code that were meant to be
untyped. Admittedly I haven't found any of these. :-)
I think I'm not yet comfortable with changing the PEP to require this
behavior, but I'm fine with introducing it in mypy and see if anyone
reports that they are inconvenienced by it (in real code).
|
That sounds like a good approach to me! |
…heckers (#133) Fixes python/typing#210. This behaviour with --fast-parser is in mypy since mid-May. It looks like nobody is complaining.
Discuss. This becomes somewhat important since we're introducing a new, faster parser in mypy that treats them as syntax errors. @ddfisher
The text was updated successfully, but these errors were encountered: