Skip to content

Commit

Permalink
Don't shorten long generic types in messages (#7997)
Browse files Browse the repository at this point in the history
Shortened names can be confusing.
  • Loading branch information
JukkaL authored and msullivan committed Nov 21, 2019
1 parent 23a719f commit d9dea5f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
6 changes: 1 addition & 5 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,15 +1438,11 @@ def format(typ: Type) -> str:
return '{}[{}]'.format(alias, ', '.join(items))
else:
# There are type arguments. Convert the arguments to strings.
# If the result is too long, replace arguments with [...].
a = [] # type: List[str]
for arg in itype.args:
a.append(format(arg))
s = ', '.join(a)
if len((base_str + s)) < 150:
return '{}[{}]'.format(base_str, s)
else:
return '{}[...]'.format(base_str)
return '{}[{}]'.format(base_str, s)
elif isinstance(typ, TypeVarType):
# This is similar to non-generic instance types.
return typ.name
Expand Down
3 changes: 1 addition & 2 deletions test-data/unit/check-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ Z = TypeVar('Z')
class OO: pass
a = None # type: A[object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object]

f(a) # E: Argument 1 to "f" has incompatible type "A[...]"; expected "OO"
f(a) # E: Argument 1 to "f" has incompatible type "A[object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object]"; expected "OO"

def f(a: OO) -> None:
pass
Expand Down Expand Up @@ -2337,4 +2337,3 @@ class Test():
reveal_type(MakeTwoAppliedSubAbstract()(2)) # N: Revealed type is '__main__.TwoTypes[builtins.str, builtins.int*]'
reveal_type(MakeTwoGenericSubAbstract[str]()('foo')) # N: Revealed type is '__main__.TwoTypes[builtins.str, builtins.str*]'
reveal_type(MakeTwoGenericSubAbstract[str]()(2)) # N: Revealed type is '__main__.TwoTypes[builtins.str, builtins.int*]'

0 comments on commit d9dea5f

Please sign in to comment.