Skip to content

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

Merged
merged 3 commits into from
Sep 2, 2017

Conversation

OddBloke
Copy link
Contributor

@OddBloke OddBloke commented Sep 2, 2017

This fixes #3899.

Copy link
Member

@ilevkivskyi ilevkivskyi left a 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(
Copy link
Member

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

@@ -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"
Copy link
Member

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)?

@OddBloke
Copy link
Contributor Author

OddBloke commented Sep 2, 2017

@ilevkivskyi Fixed.

@OddBloke
Copy link
Contributor Author

OddBloke commented Sep 2, 2017

(Thanks for the review!)

@ilevkivskyi ilevkivskyi merged commit be5c456 into python:master Sep 2, 2017
@ilevkivskyi
Copy link
Member

@OddBloke It looks like you are interested in the error messages, you might take a look at label "topic-usability", there are several issues related to error messages. For example you could start by looking at #963 that was previously attempted in #3433 by @quartox.

@OddBloke OddBloke deleted the bug/3899 branch September 2, 2017 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error message for incorrectly returning Any does not format types correctly
2 participants