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

Output distinct types when type names are ambiguous #15184

Merged
merged 4 commits into from
May 4, 2023

Conversation

teresa0605
Copy link
Contributor

Fixes #12677

When assert_type fails, when the type of value examined and the specified type have the same name, mypy returns an error with more descriptive and distinct names.

Example:

Error: Expression is of type "mypy-test.SupportsIndex", not "typing_extensions.SupportsIndex"

instead of

Error: Expression is of type "SupportsIndex", not "SupportsIndex" (previous behavior)

Testing:

Added unit tests in test-data/unit/check-assert-type-fail.test.

mypy/messages.py Outdated Show resolved Hide resolved
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Thank you!

@JelleZijlstra JelleZijlstra self-assigned this May 4, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 4, 2023

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@hauntsaninja hauntsaninja merged commit a8bd273 into python:master May 4, 2023
JelleZijlstra pushed a commit that referenced this pull request May 18, 2023
Closes #15153.

This issue was already addressed in #15184; we're adding a regression
test.
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.

assert_type: Use fully qualified types when names are ambiguous
3 participants