Commit Graph

1241 Commits

Author SHA1 Message Date
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 `TypeAliasType`s and unbound `ParamSpec`s/`TypeVar`s (#21960) 2025-12-13 20:23:16 +00:00
David Peter 82a7598aa8
[ty] Remove now-unnecessary Divergent check (#21935)
## Summary

This check is not necessary thanks to
https://github.com/astral-sh/ruff/pull/21906.
2025-12-13 16:32:09 +01:00
Douglas Creager 068eb1f500 add sig todo 2025-12-12 22:22:33 -05:00
Douglas Creager e906526578 only when function defs are same 2025-12-12 22:22:33 -05:00
Douglas Creager 25a6690cdb add materialization test 2025-12-12 22:22:33 -05:00
Douglas Creager 99ec0be478 fix test 2025-12-12 22:22:33 -05:00
Douglas Creager c94fbe20a2 Merge remote-tracking branch 'origin/main' into gggg
* origin/main: (22 commits)
  [ty] Allow gradual lower/upper bounds in a constraint set (#21957)
  [ty] disallow explicit specialization of type variables themselves (#21938)
  [ty] Improve diagnostics for unsupported binary operations and unsupported augmented assignments (#21947)
  [ty] update implicit root docs (#21955)
  [ty] Enable even more goto-definition on inlay hints (#21950)
  Document known lambda formatting deviations from Black (#21954)
  [ty] fix hover type on named expression target (#21952)
  Bump benchmark dependencies (#21951)
  Keep lambda parameters on one line and parenthesize the body if it expands (#21385)
  [ty] Improve resolution of absolute imports in tests (#21817)
  [ty] Support `__all__ += submodule.__all__`
  [ty] Change frequency of invalid `__all__` debug message
  [ty] Add `KnownUnion::to_type()` (#21948)
  [ty] Classify `cls` as class parameter (#21944)
  [ty] Stabilize rename (#21940)
  [ty] Ignore `__all__` for document and workspace symbol requests
  [ty] Attach db to background request handler task (#21941)
  [ty] Fix outdated version in publish diagnostics after `didChange` (#21943)
  [ty] avoid fixpoint unioning of types containing current-cycle Divergent (#21910)
  [ty] improve bad specialization results & error messages (#21840)
  ...
2025-12-12 22:22:11 -05:00
Douglas Creager b413a6dec4
[ty] Allow gradual lower/upper bounds in a constraint set (#21957)
We now allow the lower and upper bounds of a constraint to be gradual.
Before, we would take the top/bottom materializations of the bounds.
This required us to pass in whether the constraint was intended for a
subtyping check or an assignability check, since that would control
whether we took the "restrictive" or "permissive" materializations,
respectively.

Unfortunately, doing so means that we lost information about whether the
original query involves a non-fully-static type. This would cause us to
create specializations like `T = object` for the constraint `T ≤ Any`,
when it would be nicer to carry through the gradual type and produce `T
= Any`.

We're not currently using constraint sets for subtyping checks, nor are
we going to in the very near future. So for now, we're going to assume
that constraint sets are always used for assignability checks, and allow
the lower/upper bounds to not be fully static. Once we get to the point
where we need to use constraint sets for subtyping checks, we will
consider how best to record this information in constraints.
2025-12-12 22:18:30 -05:00
Shunsuke Shibayama e19c050386
[ty] disallow explicit specialization of type variables themselves (#21938)
## Summary

This PR makes explicit specialization of a type variable itself an
error, and the result of the specialization is `Unknown`.

The change also fixes https://github.com/astral-sh/ty/issues/1794.

## Test Plan

mdtests updated
new corpus test

---------

Co-authored-by: Carl Meyer <carl@astral.sh>
2025-12-12 15:49:20 -08:00
Alex Waygood 5a2aba237b
[ty] Improve diagnostics for unsupported binary operations and unsupported augmented assignments (#21947)
## Summary

This PR takes the improvements we made to unsupported-comparison
diagnostics in https://github.com/astral-sh/ruff/pull/21737, and extends
them to other `unsupported-operator` diagnostics.

## Test Plan

Mdtests and snapshots
2025-12-12 21:53:29 +00:00
Douglas Creager 690310cea3 not needed anymore 2025-12-12 13:05:29 -05:00
Douglas Creager e476624ef2 never? 2025-12-12 13:05:29 -05:00
Douglas Creager 2fd7a7d944 limit to valid specializations 2025-12-12 13:05:29 -05:00
Douglas Creager 2950af4fd9 calculate variance from parameter type 2025-12-12 13:05:29 -05:00
Douglas Creager 73acf0a926 whelp those are backwards 2025-12-12 13:05:25 -05:00