Commit Graph
9 Commits
Author SHA1 Message Date
Charlie Marsh b0f6523709 [ty] Preserve string annotation context in lambda defaults and TypedDicts (#27914)
## Summary

Follow-up to #27882.

Previously, changing deferred lookup modes while inferring `Annotated`
metadata could discard the enclosing string-annotation context, causing
parsed expressions to be looked up in the module's semantic index and
panic:

```python
from typing_extensions import Annotated, TypedDict

value: "Annotated[int, lambda default=int: None]"
other: "Annotated[int, TypedDict('T', {}, extra_items=int)]"
```

We now preserve `InStringAnnotation` while inferring lambda defaults.
For `TypedDict.extra_items`, we pass through the existing state and rely
on annotation inference to defer stub annotations without losing their
enclosing string context. This also covers nested lambdas, dynamic
classes in defaults, and positional-only and keyword-only stub defaults.

All 838 semantic tests pass.
2026-08-19 21:59:04 -04:00
Dhruv Manilawala c876a953dd [ty] Fix variadic signature display (#27869)
## Summary

Preserve the unpacking `*` in named variadic annotations and avoid
adding a redundant bare `*` before keyword-only parameters when `*args`
is already present. This fixes malformed revealed signatures without
changing signature storage or inference.

## Test plan

- Add a directly declared mixed-signature regression.
- Update TypeVarTuple partial, lambda, and bidirectional reveal
expectations.
- Regenerate existing single-line and multiline signature-display
snapshots.
2026-08-19 10:59:10 +05:30
Samuel RigaudandSamuel Rigaud 3f0ea98047 fix typos (#26462)
Another round of typos being fixed 

<img width="300" height="200" alt="image"
src="https://github.com/user-attachments/assets/acdaea05-0d28-4537-94db-9a809d76e00c"
/>

Co-authored-by: Samuel Rigaud <rigaud@gmail.com>
2026-07-01 23:23:21 +01:00
Ibraheem Ahmed d444d52e2b [ty] Infer lambda expressions with Callable type context (#22633)
Infer lambda expressions eagerly as part of their parent scope, and with
type context. This allows us to infer more precise types for lambda
expressions, as well as perform check assignability against `Callable`
annotations.

Note that this does not change the inferred type of a lambda parameter
with the body of the lambda, even if it is annotated. That part is a
little more tricky, so will be addressed in a followup PR.
2026-03-26 14:14:40 -04:00
Aria Desires ad3de4e488 [ty] Improve rendering of default values for function args (#22010)
## Summary

We're actually quite good at computing this but the main issue is just
that we compute it at the type-level and so wrap it in `Literal[...]`.
So just special-case the rendering of these to omit `Literal[...]` and
fallback to `...` in cases where the thing we'll show is probably
useless (i.e. `x: str = str`).

Fixes https://github.com/astral-sh/ty/issues/1882
2025-12-16 13:39:19 -05: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
lipefree f379eb6e62 [ty] Treat lambda functions as instances of types.FunctionType (#18431) 2025-06-02 16:46:26 +01:00
Alex Waygood d1bb10a66b [ty] Understand classes that inherit from subscripted Protocol[] as generic (#17832) 2025-05-09 17:39:15 +01:00
Micha Reiser b51c4f82ea Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00