-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
1 / 11 of 1 issue completedClosed
1 / 11 of 1 issue completed
Copy link
Labels
help wantedContributions especially welcomeContributions especially welcometyMulti-file analysis & type inferenceMulti-file analysis & type inference
Description
- x is not None
- [red-knot] Type narrowing for
x is None#13715 - x is not T (where T is any singleton type, incl a class or function)
- x is T
- x != T (where y is of type T with T a singleton type)
- Type narrowing for
isinstancetests #13893 - not isinstance(x, T) (where T is a class or tuple of classes)
- apply negated narrowing from previously excluded cases to
elifandelseblocks - E and F (where E and F are both supported narrowing expressions)
- E or F (where E and F are both supported narrowing expressions; reduces to (T & C(E)) | (T & C(F)), where T is the prior type of a variable and C(E) / C(F) are the constraints on it obtained from E and F)
- [red-knot] Type narrowing for
issubclasstests #14117 - not issubclass(x, T) (where T is a class or tuple of classes)
- [red-knot] Narrowing for
type(x) is C(where C is a class) #14431 - type(x) is not C (where C is a class)
- [red-knot] support narrowing on
if xandif not x#14550 - [red-knot] support narrowing on bool(E) #14547
- match-statement narrowing forms (individual TODOs in code, could break these out)
- TypeIs and TypeGuard special forms
This is not an exhaustive list of what we'll eventually want to support, it's just a starter list of some useful ones that aren't currently blocked by other type system features that aren't implemented yet.
(Supporting narrowing on x.attr or x[sub] expression forms is out of scope for this issue.)
Implementation for these lives in crates/red_knot_python_semantic/src/types/narrow.rs.
These cases we may want eventually, but we are deferring for now (please don't add support for these right now):
- x == None (not sound for most x, don't want to do it unless driven by real use cases)
- x == T (where T is any literal type) -- not sound for most x; need real use cases (maybe TypedDicts are a use case?)
- x != T (where T is any literal type) -- use cases not clear yet; could result in complex-but-useless intersections
Sub-issues
Metadata
Metadata
Assignees
Labels
help wantedContributions especially welcomeContributions especially welcometyMulti-file analysis & type inferenceMulti-file analysis & type inference