Skip to content

Commit 36f5e2e

Browse files
committed
Add additional test cases
1 parent 1f92a2c commit 36f5e2e

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

test-data/unit/check-literal.test

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,7 @@ reveal_type('bar' + d) # N: Revealed type is "Literal['barfoo']"
14321432

14331433
reveal_type(a.__add__(b)) # N: Revealed type is "builtins.int"
14341434
reveal_type(b.__add__(a)) # N: Revealed type is "builtins.int"
1435+
reveal_type(a.__add__(a)) # N: Revealed type is "builtins.int"
14351436

14361437
a *= b # E: Incompatible types in assignment (expression has type "int", variable has type "Literal[3]")
14371438
b *= a
@@ -2986,13 +2987,19 @@ class C(Base):
29862987
[builtins fixtures/tuple.pyi]
29872988

29882989
[case testLiteralAddition]
2989-
from typing import Union
2990+
from typing import Any, Union
29902991
from typing_extensions import Literal
29912992

2993+
class A:
2994+
def __add__(self, other: str) -> str: ...
2995+
def __radd__(self, other: str) -> str: ...
2996+
29922997
str_a: Literal["a"]
29932998
str_b: Literal["b"]
29942999
str_union_1: Literal["a", "b"]
29953000
str_union_2: Literal["d", "c"]
3001+
str_union_mixed_1: Union[Literal["a"], Any]
3002+
str_union_mixed_2: Union[Literal["a"], A]
29963003
s: str
29973004
int_1: Literal[1]
29983005
int_2: Literal[2]
@@ -3020,6 +3027,10 @@ reveal_type(str_a + s) # N: Revealed type is "builtins.str"
30203027
reveal_type(s + str_a) # N: Revealed type is "builtins.str"
30213028
reveal_type(str_union_1 + s) # N: Revealed type is "builtins.str"
30223029
reveal_type(s + str_union_1) # N: Revealed type is "builtins.str"
3030+
reveal_type(str_a + str_union_mixed_1) # N: Revealed type is "builtins.str"
3031+
reveal_type(str_union_mixed_1 + str_a) # N: Revealed type is "Union[builtins.str, Any]"
3032+
reveal_type(str_a + str_union_mixed_2) # N: Revealed type is "builtins.str"
3033+
reveal_type(str_union_mixed_2 + str_a) # N: Revealed type is "builtins.str"
30233034

30243035
reveal_type(1 + 2) # N: Revealed type is "builtins.int"
30253036
reveal_type(int_1 + int_2) # N: Revealed type is "Literal[3]"
@@ -3057,6 +3068,21 @@ reveal_type("a" + misc_union) # E: Unsupported operand types for + ("str" and "
30573068
# N: Revealed type is "builtins.str"
30583069
[builtins fixtures/primitives.pyi]
30593070

3071+
[case testLiteralAdditionInheritance]
3072+
class A:
3073+
a = ""
3074+
3075+
class B(A):
3076+
a = "a" + "b"
3077+
3078+
class C:
3079+
a = "a" + "b"
3080+
3081+
reveal_type(A.a) # N: Revealed type is "builtins.str"
3082+
reveal_type(B.a) # N: Revealed type is "builtins.str"
3083+
reveal_type(C.a) # N: Revealed type is "builtins.str"
3084+
[builtins fixtures/primitives.pyi]
3085+
30603086
[case testLiteralAdditionTypedDict]
30613087
from typing import TypedDict
30623088
from typing_extensions import Literal

0 commit comments

Comments
 (0)