Commit Graph

1255 Commits

Author SHA1 Message Date
Carl Meyer
0fc9e5e0e9 Merge branch 'dcreager/explicit-constriants' into cjm/callable-return-fixed
* dcreager/explicit-constriants:
  update expected output for graph display test
  store this in constraint, not node
  track whether constraints are explicit or not
  track source_order in PathAssignments
  [ty] Use `title` for configuration code fences in ty reference documentation (#21992)
2025-12-15 19:50:48 -08:00
Carl Meyer
7f7fb50a43 update expected output for graph display test 2025-12-15 18:06:47 -08:00
Douglas Creager
0b6bd9a735 store this in constraint, not node 2025-12-15 20:18:13 -05:00
Douglas Creager
c790aa7474 track whether constraints are explicit or not 2025-12-15 20:13:21 -05:00
Douglas Creager
298e2dcb4e track source_order in PathAssignments 2025-12-15 20:10:53 -05:00
Douglas Creager
44256deae3 Merge remote-tracking branch 'origin/main' into dcreager/callable-return
* origin/main:
  [ty] Consistent ordering of constraint set specializations, take 2 (#21983)
  [ty] Remove invalid statement-keyword completions in for-statements (#21979)
  [ty] Avoid caching trivial is-redundant-with calls (#21989)
2025-12-15 14:57:34 -05:00
Douglas Creager
7d3b7c5754 [ty] Consistent ordering of constraint set specializations, take 2 (#21983)
In https://github.com/astral-sh/ruff/pull/21957, we tried to use
`union_or_intersection_elements_ordering` to provide a stable ordering
of the union and intersection elements that are created when determining
which type a typevar should specialize to. @AlexWaygood [pointed
out](https://github.com/astral-sh/ruff/pull/21551#discussion_r2616543762)
that this won't work, since that provides a consistent ordering within a
single process run, but does not provide a stable ordering across runs.

This is an attempt to produce a proper stable ordering for constraint
sets, so that we end up with consistent diagnostic and test output.

We do this by maintaining a new `source_order` field on each interior
BDD node, which records when that node's constraint was added to the
set. Several of the BDD operators (`and`, `or`, etc) now have
`_with_offset` variants, which update each `source_order` in the rhs to
be larger than any of the `source_order`s in the lhs. This is what
causes that field to be in line with (a) when you add each constraint to
the set, and (b) the order of the parameters you provide to `and`, `or`,
etc. Then we sort by that new field before constructing the
union/intersection types when creating a specialization.
2025-12-15 14:24:08 -05:00
Micha Reiser
1df6544ad8 [ty] Avoid caching trivial is-redundant-with calls (#21989) 2025-12-15 18:45:03 +01:00
Douglas Creager
2897d498fd add TODO 2025-12-15 12:13:03 -05:00
Douglas Creager
4e3dd58815 fix Class3 example 2025-12-15 12:07:32 -05:00
Douglas Creager
26c847c229 add a bunch of callable reveals 2025-12-15 12:01:40 -05:00
Douglas Creager
2614be36cc add note about paramspec overloads 2025-12-15 12:01:40 -05:00
Douglas Creager
a914071640 return a slice! 2025-12-15 12:01:40 -05:00
Douglas Creager
483f34207b Revert "add canonically_ordered"
This reverts commit ddcd76c544.
2025-12-15 12:01:19 -05:00
Douglas Creager
42185b643b Revert "canonical ordering for constraint set mappings"
This reverts commit 3c811c19d4.
2025-12-15 12:00:32 -05:00
Douglas Creager
94b4dd86c0 track source_order in PathAssignments 2025-12-15 11:59:09 -05:00
Douglas Creager
dfcdbcffec Merge remote-tracking branch 'origin/main' into dcreager/callable-return
* origin/main:
  Fluent formatting of method chains (#21369)
  [ty] Avoid stack overflow when calculating inferable typevars (#21971)
  [ty] Add "qualify ..." code fix for undefined references (#21968)
  [ty] Use jemalloc on linux (#21975)
  Update MSRV to 1.90 (#21987)
  [ty] Improve check enforcing that an overloaded function must have an implementation (#21978)
  Update actions/checkout digest to 8e8c483 (#21982)
  [ty] Use `ParamSpec` without the attr for inferable check (#21934)
  [ty] Emit diagnostic when a type variable with a default is followed by one without a default (#21787)
2025-12-15 11:06:49 -05:00
Douglas Creager
f8a5d04296 Merge branch 'dcreager/source-order-constraints' into dcreager/callable-return
* dcreager/source-order-constraints: (30 commits)
  clippy
  fix test expectations (again)
  include source_order in display_graph output
  place bounds/constraints first
  don't always bump
  only fold once
  document display source_order
  more comments
  remove now-unused items
  fix test expectation
  use source order in specialize_constrained too
  document overall approach
  more comment
  reuse self source_order
  sort specialize_constrained by source_order
  lots of renaming
  remove source_order_for
  simpler source_order_for
  doc
  restore TODOs
  ...
2025-12-15 10:53:25 -05:00
Douglas Creager
cbfecfaf41 [ty] Avoid stack overflow when calculating inferable typevars (#21971)
When we calculate which typevars are inferable in a generic context, the
result might include more than the typevars bound by the generic
context. The canonical example is a generic method of a generic class:

```py
class C[A]:
    def method[T](self, t: T): ...
```

Here, the inferable typevar set of `method` contains `Self` and `T`, as
you'd expect. (Those are the typevars bound by the method.) But it also
contains `A@C`, since the implicit `Self` typevar is defined as `Self:
C[A]`. That means when we call `method`, we need to mark `A@C` as
inferable, so that we can determine the correct mapping for `A@C` at the
call site.

Fixes https://github.com/astral-sh/ty/issues/1874
2025-12-15 10:25:33 -05:00
Douglas Creager
cba45acd86 clippy 2025-12-15 10:23:37 -05:00
Douglas Creager
1dd3cf0e58 fix test expectations (again) 2025-12-15 10:22:27 -05:00
Douglas Creager
d9429754b9 include source_order in display_graph output 2025-12-15 10:19:58 -05:00
Douglas Creager
7f4893d200 place bounds/constraints first 2025-12-15 10:16:06 -05:00
Douglas Creager
88eb5eba22 don't always bump 2025-12-15 10:15:04 -05:00
Douglas Creager
63c75d85d0 only fold once 2025-12-15 09:55:17 -05:00
Douglas Creager
358185b5e2 document display source_order 2025-12-15 09:09:41 -05:00
Douglas Creager
019db2a22e more comments 2025-12-15 08:54:19 -05:00
Douglas Creager
ccb03d3b23 remove now-unused items 2025-12-15 08:40:45 -05:00
Douglas Creager
da31e138b4 fix test expectation 2025-12-15 08:39:21 -05:00
Douglas Creager
7e2ea8bd69 use source order in specialize_constrained too 2025-12-15 08:35:50 -05:00
Micha Reiser
d08e414179 Update MSRV to 1.90 (#21987) 2025-12-15 14:29:11 +01:00
Alex Waygood
0b918ae4d5 [ty] Improve check enforcing that an overloaded function must have an implementation (#21978)
## Summary

- Treat `if TYPE_CHECKING` blocks the same as stub files (the feature
requested in https://github.com/astral-sh/ty/issues/1216)
- We currently only allow `@abstractmethod`-decorated methods to omit
the implementation if they're methods in classes that have _exactly_
`ABCMeta` as their metaclass. That seems wrong -- `@abstractmethod` has
the same semantics if a class has a subclass of `ABCMeta` as its
metaclass. This PR fixes that too. (I'm actually not _totally_ sure we
should care what the class's metaclass is at all -- see discussion in
https://github.com/astral-sh/ty/issues/1877#issue-3725937441... but the
change this PR is making seems less wrong than what we have currently,
anyway.)

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

## Test Plan

Mdtests and snapshots
2025-12-15 08:56:35 +00:00
Dhruv Manilawala
ba47349c2e [ty] Use ParamSpec without the attr for inferable check (#21934)
## Summary

fixes: https://github.com/astral-sh/ty/issues/1820

## Test Plan

Add new mdtests.

Ecosystem changes removes all false positives.
2025-12-15 11:04:28 +05:30
Douglas Creager
1f34f43745 document overall approach 2025-12-14 21:57:35 -05:00
Douglas Creager
649c7bce58 more comment 2025-12-14 21:51:56 -05:00
Douglas Creager
92894d3712 reuse self source_order 2025-12-14 21:49:50 -05:00
Douglas Creager
5a8a9500b9 sort specialize_constrained by source_order 2025-12-14 19:38:07 -05:00
Douglas Creager
49ca97a20e lots of renaming 2025-12-14 19:01:44 -05:00
Douglas Creager
d223f64af1 remove source_order_for 2025-12-14 18:56:22 -05:00
Douglas Creager
a4a3aff8d6 simpler source_order_for 2025-12-14 18:47:45 -05:00
Bhuminjay Soni
04f9949711 [ty] Emit diagnostic when a type variable with a default is followed by one without a default (#21787)
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
2025-12-14 19:35:37 +00:00
Douglas Creager
bdaf8e5812 doc 2025-12-14 13:19:34 -05:00
Douglas Creager
e583cb7682 restore TODOs 2025-12-14 13:11:31 -05:00
Douglas Creager
86271d605d codex 2 2025-12-14 13:10:51 -05:00
Douglas Creager
8655598901 codex attempt 1 2025-12-14 12:56:21 -05:00
Douglas Creager
3c811c19d4 canonical ordering for constraint set mappings 2025-12-13 20:05:49 -05:00
Douglas Creager
ddcd76c544 add canonically_ordered 2025-12-13 20:03:15 -05:00
Charlie Marsh
be8eb92946 [ty] Add support for __qualname__ and other implicit class attributes (#21966)
## Summary

Closes https://github.com/astral-sh/ty/issues/1873
2025-12-13 17:10:25 -05:00
Simon Lamon
a544c59186 [ty] Emit a diagnostic when frozen dataclass inherits a non-frozen dataclass and the other way around (#21962)
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
2025-12-13 20:59:26 +00:00
Alex Waygood
bb464ed924 [ty] Use unqualified names for displays of TypeAliasTypes and unbound ParamSpecs/TypeVars (#21960) 2025-12-13 20:23:16 +00:00