ruff/crates/red_knot_python_semantic/resources/mdtest/literal/integer.md
Alex d77480768d
[red-knot] Port type inference tests to new test framework (#13719)
## Summary

Porting infer tests to new markdown tests framework.

Link to the corresponding issue: #13696

---------

Co-authored-by: Carl Meyer <carl@astral.sh>
2024-10-15 11:23:46 -07:00

806 B

Integer literals

Literals

We can infer an integer literal type:

reveal_type(1)  # revealed: Literal[1]

Variable

x = 1
reveal_type(x)  # revealed: Literal[1]

Overflow

We only track integer literals within the range of an i64:

reveal_type(9223372036854775808)  # revealed: int

Big int

We don't support big integer literals; we just infer int type instead:

x = 10_000_000_000_000_000_000
reveal_type(x)  # revealed: int

Negated

x = -1
y = -1234567890987654321
z = --987
reveal_type(x)  # revealed: Literal[-1]
reveal_type(y)  # revealed: Literal[-1234567890987654321]
reveal_type(z)  # revealed: Literal[987]

Floats

reveal_type(1.0)  # revealed: float

Complex

reveal_type(2j)  # revealed: complex