-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Missing annotation in function passed in a click decorator #3869
Comments
The issue is |
Thank you for your help. When I annotated the |
I believe we just increment the line number of the last decorator to find the function line number, which is not always accurate. We also cannot decrement from the first statement, as there may be a blank line between the nodes. Looking at the raw information of the ast parsing, I don't believe there is information on the line the annotation should be if it is absent (since the attribute |
Surely there's a line number in the AST for the 'def'? That should be less
confusing.
|
The def foo(a: int,
b: str): ... The return should be on line 2, however the |
When mypy informs me that a "Function is missing a return type annotation", all I'm wondering is "which function?" Telling me which line the def is on would answer that question. From there, I can figure out on my own that the type annotation itself should go after the parenthesis that closes the parameter list, whichever line that might be on. If mypy pointed to the exact place where the annotation should go it would indeed be a nice bit of sugar, but the essential information seems to be which line the def of the function in question is on. What confused me about the error pointing to line 6 in the original foo.py program was that it pointed a place in the decorator that contained a function call, so I (and another person helping me out on #python) both wondered if mypy was complaining that it was the function called on line 6 -- |
Yes, I understand the issue, I am unsure of how to solve it internally in mypy. We use the typed_ast module to get the line number information. I don't think the AST exposes the location of the return type, which we want. Also, in future, if you want help on mypy, you may be interested in the chat https://gitter.com/python/typing . (If you prefer IRC, there is an IRC bridge for gitter). There is almost always someone around who can help out with this. |
Dang. I didn't remember the Python AST doesn't have a separate node for the
'def' (it exists in the grammar but it's optimized out in the AST). Can you
file a new mypy issue and one in typed_ast?
|
A lot has changed since 2017, e.g. see #6753 |
When I run "mypy --disallow-any unannotated foo.py", mypy tells me that "foo.py:6: error: Function is missing a return type annotation".
Here is the output of running "mypy -v --disallow-any unannotated foo.py"
I'm not sure if this is a bug or if there's some special way I'm supposed to annotate the line mypy is complaining about.
The text was updated successfully, but these errors were encountered: