-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
is_type_comment() is wrong #2097
Comments
I think there is also the pragmas in |
Should we also standardise spaces before the colon? Meaning we would accept (and fix) e.g. |
Hey everyone! Can I get some maintainer reivews on the PR? |
@Pierre-Sassoulas Hello... I am new here and I would like to start contributing in the repository. So can you please assign this issue to me |
Hey @ishankamboj, sorry I'm not a black maintainer. I think you can start implementing right away and open a PR though :) |
hello i am new here and would like to contribute to the project can you help me out |
Hi everyone, Referring to @ichard26's comment on PR#2698:
I have a few questions:
Looking forward to the maintainers' insights on these points. Thanks! |
Yes, look at
I think so. While the typing spec does not say anything about whitespace in these comments, I believe all type checkers use whitespace insensitivity.
There are multiple possible meanings of "standardizing". I would support a clarification to the typing spec about whitespace sensitivity of type comments. I would also support a change to Black to treat whitespace in type comments correctly, but we have to be careful that we do not break Black's stability policy.
Other pragma comments are specific to individual tools. We'd have to look at those tools to figure out how they handle whitespace. |
In pylint the regex used is here: As you can easily see (😄) there can be multiple white-spaces. |
I have implemented type comment standardization, but the following tests I have written won't pass: # test type comments
def fb(
f, # type : int
h, # type: int
i, # type: int
):
# type: (...) -> None
pass
# output
# test type comments
def fb(
f, # type: int
h, # type: int
i, # type: int
):
# type: (...) -> None
pass Even though the code will be formatted correctly, the output will produce a different AST because the python ast module does not recognize the following line as a type comment: f, # type : int But if it is formatted correctly, it will: f, # type: int This is the diff given by the unit test:
Question:How should I go about implementing type comment standardization considering these issues? |
I think we shouldn't normalize whitespace between "type" and the colon. Mypy also doesn't recognize |
i am interested to contribute in this repository . please assign me |
Currently, the implementation of
is_type_comment()
looks like this:But this is wrong, because typed-ast also recognizes a comment with multiple spaces after the
#
as a type comment. Concretely this could lead Black to skip some of the checks we have to avoid moving type comments to the wrong line.Ideally, Black should also standardize the formatting of type comments by cleaning up excessive whitespace after the
#
and after the:
.The text was updated successfully, but these errors were encountered: