ruff
8716b4e2 - [ty] implement `typing.TypeGuard` (#20974)

Commit
3 days ago
[ty] implement `typing.TypeGuard` (#20974) ## Summary Resolve(s) astral-sh/ty#117, astral-sh/ty#1569 Implement `typing.TypeGuard`. Due to the fact that it [overrides anything previously known about the checked value](https://typing.python.org/en/latest/spec/narrowing.html#typeguard)--- > When a conditional statement includes a call to a user-defined type guard function, and that function returns true, the expression passed as the first positional argument to the type guard function should be assumed by a static type checker to take on the type specified in the TypeGuard return type, unless and until it is further narrowed within the conditional code block. ---we have to substantially rework the constraints system. In particular, we make constraints represented as a disjunctive normal form (DNF) where each term includes a regular constraint, and one or more disjuncts with a typeguard constraint. Some test cases (including some with more complex boolean logic) are added to `type_guards.md`. ## Test Plan - update existing tests - add new tests for more complex boolean logic with `TypeGuard` - add new tests for `TypeGuard` variance --------- Co-authored-by: Carl Meyer <carl@astral.sh>
Parents
Loading