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

Make type formatting use fullnames whenever there is ambiguity #7226

Merged
merged 4 commits into from Jul 18, 2019

Conversation

@msullivan
Copy link
Collaborator

commented Jul 16, 2019

When pretty printing types, find all groups of distinct appearing
instances that have the same short name and format them using their
fullnames.

This should eliminate error messages such as got "List[A]", expected "Sequence[A]"
(and a bunch of even less tricky ones we were messing up...).

@msullivan msullivan requested review from JukkaL and gvanrossum Jul 16, 2019
a = (a.A(), A())
a.x # E: "Tuple[a.A, b.A]" has no attribute "x"

[builtins fixtures/list.pyi]

This comment has been minimized.

Copy link
@gvanrossum

gvanrossum Jul 16, 2019

Member

I didn't read the whole diff yet, but seeing this set of tests makes me wonder, what if one of the types is a.A (i.e. not the locally defined A) and the other is, say, int? Will it correctly show a.A, or might it show just A? (Which would be confusing because in scope, A refers to b.A.)

This comment has been minimized.

Copy link
@msullivan

msullivan Jul 17, 2019

Author Collaborator

We would just show A, yeah. This is a bummer but fixing it would be much more invasive than this diff, since type formatting will need to be much more contextual.

Copy link
Collaborator

left a comment

Thanks for fixing this -- users can get quite confused about error message saying "A is not compatible with A". Left a bunch of minor things and a request for refactoring -- otherwise looks good.

mypy/messages.py Outdated Show resolved Hide resolved
mypy/messages.py Outdated Show resolved Hide resolved
mypy/messages.py Outdated Show resolved Hide resolved
mypy/messages.py Outdated Show resolved Hide resolved
mypy/messages.py Outdated Show resolved Hide resolved
mypy/messages.py Outdated Show resolved Hide resolved
mypy/messages.py Outdated Show resolved Hide resolved
mypy/type_visitor.py Outdated Show resolved Hide resolved
msullivan added 4 commits Jul 16, 2019
When pretty printing types, find all groups of distinct appearing
instances that have the same short name and format them using their
fullnames.

This should eliminate error messages such as `got "List[A]", expected
Sequence[A]` (and a bunch of even less tricky ones we were messing
up...).
@msullivan msullivan force-pushed the messages2 branch from e794688 to a25c448 Jul 18, 2019
@msullivan msullivan merged commit 55375f6 into master Jul 18, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@msullivan msullivan deleted the messages2 branch Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.