@@ -6,7 +6,7 @@ class Medal(Enum):
6
6
gold = 1
7
7
silver = 2
8
8
bronze = 3
9
- reveal_type(Medal.bronze) # N: Revealed type is '__main__.Medal* '
9
+ reveal_type(Medal.bronze) # N: Revealed type is 'Literal[ __main__.Medal.bronze]? '
10
10
m = Medal.gold
11
11
if int():
12
12
m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Medal")
@@ -20,7 +20,7 @@ class Medal(metaclass=EnumMeta):
20
20
# Without __init__ the definition fails at runtime, but we want to verify that mypy
21
21
# uses `enum.EnumMeta` and not `enum.Enum` as the definition of what is enum.
22
22
def __init__(self, *args): pass
23
- reveal_type(Medal.bronze) # N: Revealed type is '__main__.Medal'
23
+ reveal_type(Medal.bronze) # N: Revealed type is 'Literal[ __main__.Medal.bronze]? '
24
24
m = Medal.gold
25
25
if int():
26
26
m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Medal")
@@ -34,7 +34,7 @@ class Medal(Achievement):
34
34
bronze = None
35
35
# See comment in testEnumFromEnumMetaBasics
36
36
def __init__(self, *args): pass
37
- reveal_type(Medal.bronze) # N: Revealed type is '__main__.Medal'
37
+ reveal_type(Medal.bronze) # N: Revealed type is 'Literal[ __main__.Medal.bronze]? '
38
38
m = Medal.gold
39
39
if int():
40
40
m = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Medal")
@@ -53,7 +53,7 @@ class Truth(Enum):
53
53
false = False
54
54
x = ''
55
55
x = Truth.true.name
56
- reveal_type(Truth.true.name) # N: Revealed type is 'builtins.str '
56
+ reveal_type(Truth.true.name) # N: Revealed type is 'Literal['true']? '
57
57
reveal_type(Truth.false.value) # N: Revealed type is 'builtins.bool'
58
58
[builtins fixtures/bool.pyi]
59
59
@@ -246,7 +246,7 @@ class A:
246
246
a = A()
247
247
reveal_type(a.x)
248
248
[out]
249
- main:8: note: Revealed type is '__main__.E@4* '
249
+ main:8: note: Revealed type is '__main__.E@4'
250
250
251
251
[case testEnumInClassBody]
252
252
from enum import Enum
@@ -270,9 +270,9 @@ reveal_type(E.bar.value)
270
270
reveal_type(I.bar)
271
271
reveal_type(I.baz.value)
272
272
[out]
273
- main:4: note: Revealed type is '__main__.E* '
273
+ main:4: note: Revealed type is 'Literal[ __main__.E.foo]? '
274
274
main:5: note: Revealed type is 'Any'
275
- main:6: note: Revealed type is '__main__.I* '
275
+ main:6: note: Revealed type is 'Literal[ __main__.I.bar]? '
276
276
main:7: note: Revealed type is 'builtins.int'
277
277
278
278
[case testFunctionalEnumListOfStrings]
@@ -282,8 +282,8 @@ F = IntEnum('F', ['bar', 'baz'])
282
282
reveal_type(E.foo)
283
283
reveal_type(F.baz)
284
284
[out]
285
- main:4: note: Revealed type is '__main__.E* '
286
- main:5: note: Revealed type is '__main__.F* '
285
+ main:4: note: Revealed type is 'Literal[ __main__.E.foo]? '
286
+ main:5: note: Revealed type is 'Literal[ __main__.F.baz]? '
287
287
288
288
[case testFunctionalEnumListOfPairs]
289
289
from enum import Enum, IntEnum
@@ -294,10 +294,10 @@ reveal_type(F.baz)
294
294
reveal_type(E.foo.value)
295
295
reveal_type(F.bar.name)
296
296
[out]
297
- main:4: note: Revealed type is '__main__.E* '
298
- main:5: note: Revealed type is '__main__.F* '
299
- main:6: note: Revealed type is 'builtins.int '
300
- main:7: note: Revealed type is 'builtins.str '
297
+ main:4: note: Revealed type is 'Literal[ __main__.E.foo]? '
298
+ main:5: note: Revealed type is 'Literal[ __main__.F.baz]? '
299
+ main:6: note: Revealed type is 'Literal[1]? '
300
+ main:7: note: Revealed type is 'Literal['bar']? '
301
301
302
302
[case testFunctionalEnumDict]
303
303
from enum import Enum, IntEnum
@@ -308,10 +308,10 @@ reveal_type(F.baz)
308
308
reveal_type(E.foo.value)
309
309
reveal_type(F.bar.name)
310
310
[out]
311
- main:4: note: Revealed type is '__main__.E* '
312
- main:5: note: Revealed type is '__main__.F* '
313
- main:6: note: Revealed type is 'builtins.int '
314
- main:7: note: Revealed type is 'builtins.str '
311
+ main:4: note: Revealed type is 'Literal[ __main__.E.foo]? '
312
+ main:5: note: Revealed type is 'Literal[ __main__.F.baz]? '
313
+ main:6: note: Revealed type is 'Literal[1]? '
314
+ main:7: note: Revealed type is 'Literal['bar']? '
315
315
316
316
[case testFunctionalEnumErrors]
317
317
from enum import Enum, IntEnum
@@ -363,10 +363,10 @@ main:22: error: "Type[W]" has no attribute "c"
363
363
from enum import Flag, IntFlag
364
364
A = Flag('A', 'x y')
365
365
B = IntFlag('B', 'a b')
366
- reveal_type(A.x) # N: Revealed type is '__main__.A* '
367
- reveal_type(B.a) # N: Revealed type is '__main__.B* '
368
- reveal_type(A.x.name) # N: Revealed type is 'builtins.str '
369
- reveal_type(B.a.name) # N: Revealed type is 'builtins.str '
366
+ reveal_type(A.x) # N: Revealed type is 'Literal[ __main__.A.x]? '
367
+ reveal_type(B.a) # N: Revealed type is 'Literal[ __main__.B.a]? '
368
+ reveal_type(A.x.name) # N: Revealed type is 'Literal['x']? '
369
+ reveal_type(B.a.name) # N: Revealed type is 'Literal['a']? '
370
370
371
371
# TODO: The revealed type should be 'int' here
372
372
reveal_type(A.x.value) # N: Revealed type is 'Any'
@@ -381,7 +381,7 @@ class A:
381
381
a = A()
382
382
reveal_type(a.x)
383
383
[out]
384
- main:7: note: Revealed type is '__main__.A.E@4* '
384
+ main:7: note: Revealed type is '__main__.A.E@4'
385
385
386
386
[case testFunctionalEnumInClassBody]
387
387
from enum import Enum
@@ -451,19 +451,19 @@ F = Enum('F', 'a b')
451
451
[rechecked]
452
452
[stale]
453
453
[out1]
454
- main:2: note: Revealed type is 'm.E* '
455
- main:3: note: Revealed type is 'm.F* '
454
+ main:2: note: Revealed type is 'Literal[ m.E.a]? '
455
+ main:3: note: Revealed type is 'Literal[ m.F.b]? '
456
456
[out2]
457
- main:2: note: Revealed type is 'm.E* '
458
- main:3: note: Revealed type is 'm.F* '
457
+ main:2: note: Revealed type is 'Literal[ m.E.a]? '
458
+ main:3: note: Revealed type is 'Literal[ m.F.b]? '
459
459
460
460
[case testEnumAuto]
461
461
from enum import Enum, auto
462
462
class Test(Enum):
463
463
a = auto()
464
464
b = auto()
465
465
466
- reveal_type(Test.a) # N: Revealed type is '__main__.Test* '
466
+ reveal_type(Test.a) # N: Revealed type is 'Literal[ __main__.Test.a]? '
467
467
[builtins fixtures/primitives.pyi]
468
468
469
469
[case testEnumAttributeAccessMatrix]
@@ -689,31 +689,31 @@ else:
689
689
690
690
if x is z:
691
691
reveal_type(x) # N: Revealed type is 'Literal[__main__.Foo.A]'
692
- reveal_type(z) # N: Revealed type is '__main__.Foo* '
692
+ reveal_type(z) # N: Revealed type is 'Literal[ __main__.Foo.A]? '
693
693
accepts_foo_a(z)
694
694
else:
695
695
reveal_type(x) # N: Revealed type is 'Union[Literal[__main__.Foo.B], Literal[__main__.Foo.C]]'
696
- reveal_type(z) # N: Revealed type is '__main__.Foo* '
696
+ reveal_type(z) # N: Revealed type is 'Literal[ __main__.Foo.A]? '
697
697
accepts_foo_a(z)
698
698
if z is x:
699
699
reveal_type(x) # N: Revealed type is 'Literal[__main__.Foo.A]'
700
- reveal_type(z) # N: Revealed type is '__main__.Foo* '
700
+ reveal_type(z) # N: Revealed type is 'Literal[ __main__.Foo.A]? '
701
701
accepts_foo_a(z)
702
702
else:
703
703
reveal_type(x) # N: Revealed type is 'Union[Literal[__main__.Foo.B], Literal[__main__.Foo.C]]'
704
- reveal_type(z) # N: Revealed type is '__main__.Foo* '
704
+ reveal_type(z) # N: Revealed type is 'Literal[ __main__.Foo.A]? '
705
705
accepts_foo_a(z)
706
706
707
707
if y is z:
708
708
reveal_type(y) # N: Revealed type is 'Literal[__main__.Foo.A]'
709
- reveal_type(z) # N: Revealed type is '__main__.Foo* '
709
+ reveal_type(z) # N: Revealed type is 'Literal[ __main__.Foo.A]? '
710
710
accepts_foo_a(z)
711
711
else:
712
712
reveal_type(y) # No output: this branch is unreachable
713
713
reveal_type(z) # No output: this branch is unreachable
714
714
if z is y:
715
715
reveal_type(y) # N: Revealed type is 'Literal[__main__.Foo.A]'
716
- reveal_type(z) # N: Revealed type is '__main__.Foo* '
716
+ reveal_type(z) # N: Revealed type is 'Literal[ __main__.Foo.A]? '
717
717
accepts_foo_a(z)
718
718
else:
719
719
reveal_type(y) # No output: this branch is unreachable
0 commit comments