Skip to content
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

Improve error message for incompatible TypeVar value #3707

Merged
merged 3 commits into from
Aug 1, 2017

Conversation

ilinum
Copy link
Collaborator

@ilinum ilinum commented Jul 12, 2017

Fixes #3341

@ddfisher
Copy link
Collaborator

@JukkaL what do you think of the updated error message?

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 13, 2017

Looks reasonable! Here's another alternative that would make the error message perhaps even clearer:

Current:     Type argument 1 of "f" (TypeVar "AnyStr") cannot be "object"
Alternative: Value of type variable "AnyStr" of "f" cannot be "object"

It may also make sense to special case typing.AnyStr since it's so common. Here's an idea:

t.py:1: error: Value of type variable "AnyStr" of "f" cannot be "object"
t.py:1: note: Maybe you are mixing "str" and "bytes" values, which is not supported with "AnyStr"?

@ilinum
Copy link
Collaborator Author

ilinum commented Jul 14, 2017

Both sounds good!

Regarding the first suggestion though, I think there might be a case where specifying type argument number is useful (when names of two type args are the same).

@ilevkivskyi
Copy link
Member

Note that there is PR #3433 that takes a more "global" approach to the AnyStr error message. @quartox are you still working on it?

@quartox
Copy link
Contributor

quartox commented Jul 14, 2017

@ilevkivskyi I will get back to it this weekend.

@ilinum
Copy link
Collaborator Author

ilinum commented Jul 20, 2017

I updated the error message as per Jukka's suggestion.

However, I think the additional error message for AnyStr should be handled in #3433 since @quartox is already working on it.

Copy link
Collaborator

@ddfisher ddfisher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ddfisher
Copy link
Collaborator

ddfisher commented Aug 1, 2017

And agreed -- the AnyStr change can happen in #3433.

@ddfisher ddfisher merged commit e0de8be into python:master Aug 1, 2017
@ilinum ilinum deleted the better-error-message-typevar-bound branch August 1, 2017 23:42
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.

5 participants