mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
[ty] implement disjointness of Callable vs SpecialForm (#18503)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
## Summary Fixes https://github.com/astral-sh/ty/issues/557 ## Test Plan Stable property tests succeed with a million iterations. Added mdtests. --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
eb60bd64fd
commit
a2de81cb27
3 changed files with 109 additions and 0 deletions
|
@ -498,3 +498,50 @@ def possibly_unbound_with_invalid_type(flag: bool):
|
|||
static_assert(is_disjoint_from(G, Callable[..., Any]))
|
||||
static_assert(is_disjoint_from(Callable[..., Any], G))
|
||||
```
|
||||
|
||||
A callable type is disjoint from special form types, except for callable special forms.
|
||||
|
||||
```py
|
||||
from ty_extensions import is_disjoint_from, static_assert, TypeOf
|
||||
from typing_extensions import Any, Callable, TypedDict
|
||||
from typing import Literal, Union, Optional, Final, Type, ChainMap, Counter, OrderedDict, DefaultDict, Deque
|
||||
|
||||
# Most special forms are disjoint from callable types because they are
|
||||
# type constructors/annotations that are subscripted, not called.
|
||||
static_assert(is_disjoint_from(Callable[..., Any], TypeOf[Literal]))
|
||||
static_assert(is_disjoint_from(TypeOf[Literal], Callable[..., Any]))
|
||||
|
||||
static_assert(is_disjoint_from(Callable[[], None], TypeOf[Union]))
|
||||
static_assert(is_disjoint_from(TypeOf[Union], Callable[[], None]))
|
||||
|
||||
static_assert(is_disjoint_from(Callable[[int], str], TypeOf[Optional]))
|
||||
static_assert(is_disjoint_from(TypeOf[Optional], Callable[[int], str]))
|
||||
|
||||
static_assert(is_disjoint_from(Callable[..., Any], TypeOf[Type]))
|
||||
static_assert(is_disjoint_from(TypeOf[Type], Callable[..., Any]))
|
||||
|
||||
static_assert(is_disjoint_from(Callable[..., Any], TypeOf[Final]))
|
||||
static_assert(is_disjoint_from(TypeOf[Final], Callable[..., Any]))
|
||||
|
||||
static_assert(is_disjoint_from(Callable[..., Any], TypeOf[Callable]))
|
||||
static_assert(is_disjoint_from(TypeOf[Callable], Callable[..., Any]))
|
||||
|
||||
# However, some special forms are callable (TypedDict and collection constructors)
|
||||
static_assert(not is_disjoint_from(Callable[..., Any], TypeOf[TypedDict]))
|
||||
static_assert(not is_disjoint_from(TypeOf[TypedDict], Callable[..., Any]))
|
||||
|
||||
static_assert(not is_disjoint_from(Callable[..., Any], TypeOf[ChainMap]))
|
||||
static_assert(not is_disjoint_from(TypeOf[ChainMap], Callable[..., Any]))
|
||||
|
||||
static_assert(not is_disjoint_from(Callable[..., Any], TypeOf[Counter]))
|
||||
static_assert(not is_disjoint_from(TypeOf[Counter], Callable[..., Any]))
|
||||
|
||||
static_assert(not is_disjoint_from(Callable[..., Any], TypeOf[DefaultDict]))
|
||||
static_assert(not is_disjoint_from(TypeOf[DefaultDict], Callable[..., Any]))
|
||||
|
||||
static_assert(not is_disjoint_from(Callable[..., Any], TypeOf[Deque]))
|
||||
static_assert(not is_disjoint_from(TypeOf[Deque], Callable[..., Any]))
|
||||
|
||||
static_assert(not is_disjoint_from(Callable[..., Any], TypeOf[OrderedDict]))
|
||||
static_assert(not is_disjoint_from(TypeOf[OrderedDict], Callable[..., Any]))
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue