Skip to content

Commit 96db3a0

Browse files
authored
Don't simplify tuple/union types in error messages (#9360)
Address issue #9358.
1 parent a6ab81e commit 96db3a0

File tree

4 files changed

+5
-11
lines changed

4 files changed

+5
-11
lines changed

mypy/messages.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,10 +1626,7 @@ def format(typ: Type) -> str:
16261626
for t in typ.items:
16271627
items.append(format(t))
16281628
s = 'Tuple[{}]'.format(', '.join(items))
1629-
if len(s) < 400:
1630-
return s
1631-
else:
1632-
return '<tuple: {} items>'.format(len(items))
1629+
return s
16331630
elif isinstance(typ, TypedDictType):
16341631
# If the TypedDictType is named, return the name
16351632
if not typ.is_anonymous():
@@ -1661,10 +1658,7 @@ def format(typ: Type) -> str:
16611658
for t in typ.items:
16621659
items.append(format(t))
16631660
s = 'Union[{}]'.format(', '.join(items))
1664-
if len(s) < 400:
1665-
return s
1666-
else:
1667-
return '<union: {} items>'.format(len(items))
1661+
return s
16681662
elif isinstance(typ, NoneType):
16691663
return 'None'
16701664
elif isinstance(typ, AnyType):

test-data/unit/check-tuples.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ class LongTypeName:
763763
def __add__(self, x: 'LongTypeName') -> 'LongTypeName': pass
764764
[builtins fixtures/tuple.pyi]
765765
[out]
766-
main:3: error: Unsupported operand types for + ("LongTypeName" and <tuple: 50 items>)
766+
main:3: error: Unsupported operand types for + ("LongTypeName" and "Tuple[LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName, LongTypeName]")
767767

768768

769769
-- Tuple methods

test-data/unit/check-unions.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ x: Union[ExtremelyLongTypeNameWhichIsGenericSoWeCanUseItMultipleTimes[int],
974974

975975
def takes_int(arg: int) -> None: pass
976976

977-
takes_int(x) # E: Argument 1 to "takes_int" has incompatible type <union: 6 items>; expected "int"
977+
takes_int(x) # E: Argument 1 to "takes_int" has incompatible type "Union[ExtremelyLongTypeNameWhichIsGenericSoWeCanUseItMultipleTimes[int], ExtremelyLongTypeNameWhichIsGenericSoWeCanUseItMultipleTimes[object], ExtremelyLongTypeNameWhichIsGenericSoWeCanUseItMultipleTimes[float], ExtremelyLongTypeNameWhichIsGenericSoWeCanUseItMultipleTimes[str], ExtremelyLongTypeNameWhichIsGenericSoWeCanUseItMultipleTimes[Any], ExtremelyLongTypeNameWhichIsGenericSoWeCanUseItMultipleTimes[bytes]]"; expected "int"
978978

979979
[case testRecursiveForwardReferenceInUnion]
980980

test-data/unit/check-warnings.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def g() -> Any: pass
181181
def f() -> typ: return g()
182182
[builtins fixtures/tuple.pyi]
183183
[out]
184-
main:11: error: Returning Any from function declared to return <tuple: 91 items>
184+
main:11: error: Returning Any from function declared to return "Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int]"
185185

186186
[case testReturnAnySilencedFromTypedFunction]
187187
# flags: --warn-return-any

0 commit comments

Comments
 (0)