Skip to content

Commit 0b82574

Browse files
committed
Union repr uses [] not ()
1 parent f2c1372 commit 0b82574

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

mypy/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def format_simple(self, typ: Type) -> str:
197197
items = []
198198
for t in (cast(UnionType, typ)).items:
199199
items.append(strip_quotes(self.format(t)))
200-
s = '"Union({})"'.format(', '.join(items))
200+
s = '"Union[{}]"'.format(', '.join(items))
201201
if len(s) < 40:
202202
return s
203203
else:

mypy/test/data/check-unions.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ i = Undefined # type: int
7373
x.foo()
7474
y.foo()
7575
i = x.foo()
76-
i = y.foo() # E: Incompatible types in assignment (expression has type "Union(int, str)", variable has type "int")
76+
i = y.foo() # E: Incompatible types in assignment (expression has type "Union[int, str]", variable has type "int")
7777

7878
[builtins fixtures/isinstance.py]
7979

mypy/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def accept(self, visitor: 'TypeVisitor[T]') -> T:
388388

389389

390390
class UnionType(Type):
391-
"""The union type Union(T1, ..., Tn) (at least one type argument)."""
391+
"""The union type Union[T1, ..., Tn] (at least one type argument)."""
392392

393393
items = Undefined(List[Type])
394394

@@ -676,7 +676,7 @@ def visit_tuple_type(self, t):
676676

677677
def visit_union_type(self, t):
678678
s = self.list_str(t.items)
679-
return 'Union({})'.format(s)
679+
return 'Union[{}]'.format(s)
680680

681681
def visit_runtime_type_var(self, t):
682682
return '<RuntimeTypeVar>'

0 commit comments

Comments
 (0)