-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Format types nicely in incorrectly-returning-Any warning #3910
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just few suggestions.
mypy/messages.py
Outdated
@@ -1005,6 +1004,11 @@ def disallowed_any_type(self, typ: Type, context: Context) -> None: | |||
message = 'Expression type contains "Any" (has type {})'.format(self.format(typ)) | |||
self.fail(message, context) | |||
|
|||
def incorrectly_returning_any(self, typ: Type, context: Context) -> None: | |||
message = 'Returning Any from function with declared return type {}'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error might sound awkward in situations like:
Returning Any from function with declared return type <nothing>
Returning Any from function with declared return type overloaded function
Returning Any from function with declared return type Module
I think it will sound better if you say something like
Returning Any from function declared to return <nothing>
Returning Any from function declared to return overloaded function
Returning Any from function declared to return Module
test-data/unit/check-warnings.test
Outdated
@@ -141,7 +141,7 @@ from typing import Any | |||
def g() -> Any: pass | |||
def f() -> int: return g() | |||
[out] | |||
main:4: warning: Returning Any from function with declared return type "builtins.int" | |||
main:4: warning: Returning Any from function with declared return type "int" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add one more test for situations where the special formatting takes place (like with callable types and/or long unions and/or NoReturn
and/or module type)?
@ilevkivskyi Fixed. |
(Thanks for the review!) |
This fixes #3899.