Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -5115,6 +5115,28 @@ main:2: note: Revealed type is "builtins.int"
[out2]
main:2: note: Revealed type is "Literal[2]"

[case testLiteralIncrementalBigInts]
import a
[file a.py]
import mod
reveal_type(mod.x)
[file a.py.2]
import mod
reveal_type(mod.x)
reveal_type(mod.f)
[file mod.py]
from typing import Literal
x: Literal[18446744073709551616, -9223372036854775809, 0xCBF29CE484222325]
def f(x: Literal[-0x_FFFF_FFFF_FFFF_FFFF_FFFF]) -> None: ...
[builtins fixtures/tuple.pyi]
[rechecked a]
[stale]
[out]
tmp/a.py:2: note: Revealed type is "Literal[18446744073709551616] | Literal[-9223372036854775809] | Literal[14695981039346656037]"
[out2]
tmp/a.py:2: note: Revealed type is "Literal[18446744073709551616] | Literal[-9223372036854775809] | Literal[14695981039346656037]"
tmp/a.py:3: note: Revealed type is "def (x: Literal[-1208925819614629174706175])"

[case testAddedSubStarImport]
# cmd: mypy -m a pack pack.mod b
# cmd2: mypy -m other
Expand Down
40 changes: 40 additions & 0 deletions test-data/unit/check-literal.test
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,46 @@ reveal_type(f4) # N: Revealed type is "def (x: Literal[8]) -> Literal[8]"
[builtins fixtures/tuple.pyi]
[out]

[case testLiteralBigIntUsage]
from typing import Final, Literal
import mod

a1: Literal[9223372036854775808]
b1: Literal[-9223372036854775809]
c1: Literal[18_446_744_073_709_551_615]
d1: Literal[0xCBF29CE484222325]
e1: "Literal[-18446744073709551616]"
f1 = 18446744073709551616 # type: Literal[18446744073709551616]

reveal_type(a1) # N: Revealed type is "Literal[9223372036854775808]"
reveal_type(b1) # N: Revealed type is "Literal[-9223372036854775809]"
reveal_type(c1) # N: Revealed type is "Literal[18446744073709551615]"
reveal_type(d1) # N: Revealed type is "Literal[14695981039346656037]"
reveal_type(e1) # N: Revealed type is "Literal[-18446744073709551616]"
reveal_type(f1) # N: Revealed type is "Literal[18446744073709551616]"
reveal_type(mod.FNV_OFFSET) # N: Revealed type is "Literal[14695981039346656037]"

a2t = Literal[9223372036854775808]
b2t = Literal[-9223372036854775809]
a2: a2t
b2: b2t

reveal_type(a2) # N: Revealed type is "Literal[9223372036854775808]"
reveal_type(b2) # N: Revealed type is "Literal[-9223372036854775809]"

def f(x: Literal[0xCBF29CE484222325]) -> Literal[-0xCBF29CE484222325]: pass
reveal_type(f) # N: Revealed type is "def (x: Literal[14695981039346656037]) -> Literal[-14695981039346656037]"

FNV: Final = 0xCBF29CE484222325
f(FNV)
f(14695981039346656037)
f(14695981039346656038) # E: Argument 1 to "f" has incompatible type "Literal[14695981039346656038]"; expected "Literal[14695981039346656037]"
[file mod.pyi]
from typing import Literal
FNV_OFFSET: Literal[0xCBF29CE484222325]
[builtins fixtures/tuple.pyi]
[out]

[case testLiteralBasicBoolUsage]
from typing import Literal

Expand Down
45 changes: 45 additions & 0 deletions test-data/unit/native-parser.test
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,51 @@ MypyFile:1(
Any)
Literal?[-1, 0, 1]))

[case testLiteralBigIntTypes]
a: Literal[9223372036854775807, -9223372036854775808]
b: Literal[9223372036854775808, -9223372036854775809]
c: Literal[18_446_744_073_709_551_615, 0xCBF29CE484222325, 0o7777777777777777777777777]
d: Literal[-0x_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF, +0b1_0000000000000000000000000000000000000000000000000000000000000000]
e: Literal[+5, -+5, --5, --18446744073709551616]
f: "Literal[18446744073709551616]"
g = 1 # type: Literal[-18446744073709551616]
[out]
MypyFile:1(
AssignmentStmt:1(
NameExpr(a)
TempNode:1(
Any)
Literal?[9223372036854775807, -9223372036854775808])
AssignmentStmt:2(
NameExpr(b)
TempNode:2(
Any)
Literal?[9223372036854775808, -9223372036854775809])
AssignmentStmt:3(
NameExpr(c)
TempNode:3(
Any)
Literal?[18446744073709551615, 14695981039346656037, 37778931862957161709567])
AssignmentStmt:4(
NameExpr(d)
TempNode:4(
Any)
Literal?[-340282366920938463463374607431768211455, 18446744073709551616])
AssignmentStmt:5(
NameExpr(e)
TempNode:5(
Any)
Literal?[5, -5, 5, 18446744073709551616])
AssignmentStmt:6(
NameExpr(f)
TempNode:6(
Any)
Literal?[18446744073709551616])
AssignmentStmt:7(
NameExpr(g)
IntExpr(1)
Literal?[-18446744073709551616]))

[case testDelStmt]
del x
del x[0], y[1]
Expand Down
Loading