Commit Graph
7 Commits
Author SHA1 Message Date
Charlie Marsh 9501d97402 [ty] Simplify numeric tower displays (e.g., float over int | float) (#27406)
## Summary

PEP 484's numeric tower means we represent a `float` annotation as the
semantic union `int | float*` and `complex` as `int | float* |
complex*`. We previously rendered those internal unions directly, which
exposed an implementation detail in user-facing output:

```python
def f() -> float:
    return 1

reveal_type(f())  # Before: int | float; after: float
```

This change recognizes complete numeric-tower unions during display and
renders them using their canonical annotation spelling, `float` or
`complex`.

The implementation does _not_ preserve explicit unions, e.g., if the
user writes out `int | float`, we still collapse that rather than trying
to preserve it, mostly for simplicity (as per
https://github.com/astral-sh/ty/issues/2184#issuecomment-4345219164).

Closes https://github.com/astral-sh/ty/issues/2184.
2026-08-05 21:29:29 +00:00
Alex WaygoodandBrandt Bucher a2f546b254 [ty] Infer precise types for bit-shift operations on integer literals (#23301)
## Summary

Fixes https://github.com/astral-sh/ty/issues/517.

This PR revives https://github.com/astral-sh/ruff/pull/18329 /
https://github.com/astral-sh/ruff/pull/19281, but without the
controversial bit of those PRs (the new diagnostic). Rather than adding
a new diagnostic if an integer is left-shifted or right-shifted by a
negative number, we just ignore that and infer `int`. We can always add
a new diagnostic later, if we find consensus on it.

Along the way, Claude also discovered that
`reveal_type(-(-9223372036854775807 - 1))` currently reveals
`Literal[-9223372036854775808]` on `main`, which is... not correct. So
this PR fixes that too.

### Test Coverage

mdtests

Co-authored-by: Brandt Bucher <brandt@python.org>
2026-02-16 03:42:36 +00:00
Luca Chiodini 5a9d6a91ea [ty] Uniformly use "not supported" in diagnostics (#21916) 2025-12-11 15:03:55 +00:00
Carl Meyer 6b7adb0537 [ty] support PEP 613 type aliases (#21394)
Refs https://github.com/astral-sh/ty/issues/544

## Summary

Takes a more incremental approach to PEP 613 type alias support (vs
https://github.com/astral-sh/ruff/pull/20107). Instead of eagerly
inferring the RHS of a PEP 613 type alias as a type expression, infer it
as a value expression, just like we do for implicit type aliases, taking
advantage of the same support for e.g. unions and other type special
forms.

The main reason I'm following this path instead of the one in
https://github.com/astral-sh/ruff/pull/20107 is that we've realized that
people do sometimes use PEP 613 type aliases as values, not just as
types (because they are just a normal runtime assignment, unlike PEP 695
type aliases which create an opaque `TypeAliasType`).

This PR doesn't yet provide full support for recursive type aliases
(they don't panic, but they just fall back to `Unknown` at the recursion
point). This is future work.

## Test Plan

Added mdtests.

Many new ecosystem diagnostics, mostly because we
understand new types in lots of places.

Conformance suite changes are correct.

Performance regression is due to understanding lots of new
types; nothing we do in this PR is inherently expensive.
2025-11-20 17:59:35 -08:00
Brandt Bucher 91b7a570c2 [ty] Implement Python's floor division semantics for Literal ints (#18249)
Division works differently in Python than in Rust. If the result is
negative and there is a remainder, the division rounds down (instead of
towards zero). The remainder needs to be adjusted to compensate so that
`(lhs // rhs) * rhs + (lhs % rhs) == lhs`.

Fixes astral-sh/ty#481.
2025-05-22 10:42:29 -04:00
Alex Waygood 67cd94ed64 [ty] Add missing bitwise-operator branches for boolean and integer arithmetic (#17949) 2025-05-08 14:10:35 +01:00
Micha Reiser b51c4f82ea Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00