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

Highlight differences in complex types #4531

Open
JukkaL opened this issue Feb 1, 2018 · 0 comments
Open

Highlight differences in complex types #4531

JukkaL opened this issue Feb 1, 2018 · 0 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 1, 2018

Sometimes it's hard to see why two types are incompatible if they are long and almost the same. Dummy example:

from typing import Callable
from mypy_extensions import Arg

x: Callable[[Arg(int, 'foobar'), Arg(int, 'bir'), Arg(int, 'fubar')], None]
y: Callable[
    [Arg(int, 'foobar'), Arg(int, 'blr'), Arg(int, 'fubar')], None]

x = y

This is the error:

t.py:7: error: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'foobar'), Arg(int, 'blr'), Arg(int, 'fubar')], None]", variable has type "Callable[[Arg(int, 'foobar'), Arg(int, 'bir'), Arg(int, 'fubar')], None]")

Here's a potential better message that highlights the difference:

t.py:7: error: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'foobar'), Arg(int, 'blr'), Arg(int, 'fubar')], None]", variable has type "Callable[[Arg(int, 'foobar'), Arg(int, 'bir'), Arg(int, 'fubar')], None]")
t.py:7: note: Expression type: ..., Arg(int, 'blr'), ...
t.py:7: note: Variable type:   ..., Arg(int, 'bir'), ...
t.py:7: note:                                 ^^^

It's not clear what's the best way to generalize this sort of "type diff" to arbitrary nested types and to arbitrary type differences. We should at least handle some typical cases. We could also look at how other (non-Python) language implementations handle this.

Just splitting long lines and aligning them would help a bit (but in general the alignment could be off, since there could be multiple differences in types, only some of which are problematic):

t.py:7: error: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'foobar'), Arg(int, 'blr'), Arg(int, 'fubar')], None]", 
t.py:7: error:                                     variable has type "Callable[[Arg(int, 'foobar'), Arg(int, 'bir'), Arg(int, 'fubar')], None]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants