-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Support multi-line # type: comments for inline types #4511
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
Comments
Mypy follows PEP 484 in this respect. Changes should be proposed at https://github.com/python/typing/issues. There are a few things that can help:
Maybe we should add this to common issues in mypy documentation? |
@JukkaL Thanks for the tip. I'll open the issue there shortly.
Yes, please. The way I've worked around this for now is by escaping the newline. However, this is ugly and should be unnecessary. def test(pools):
really_long_attribute = collections.defaultdict(list) \
# type: DefaultDict[str, List[str]]
for pool in pools:
pass # meaningful stuff in here |
Reported in python/typing#534 |
Actually escaping the newline is a perfectly reasonable solution and avoids
the ambiguity of putting the type comment on a separate line (someone not
familiar with this convention might wonder if it applies to the previous
line or to the next).
|
Escaping the newline is not really a solution if the type signature by itself doesn't fit on one line though. |
Agree. In a lot of cases, the type signature would be very long, especially with Callables. |
This is less of an issue now that all alive Pythons support PEP 526 |
#1102 provided a way to split
# type:
comments over multiple lines for functions, however, there doesn't seem to be such a thing to split markup for inline attributes. For example:The text was updated successfully, but these errors were encountered: