Improve typing support for the UNSET symbol.
Review Request #13191 — Created Aug. 7, 2023 and submitted
This reworks the internals of the UNSET symbol (which was introduced in
Djblets 3.3) and makes it easier to integrate it with typing logic and
type checkers.
UnsetSymbol
is now anEnum
, allowingUNSET
to be defined as a
Literal
. This works along with a newUnsettable[_T]
type alias to
mark whether a parameter or variable allowsUNSET
to be set.By making this a
Literal
, type checkers can type narrow when a code
compares a value toUNSET
, avoiding any type errors that still wanted
to considerUnsetSymbol
a possible value.
Made use of this in some in-progress code. Verified that mypy and pyright
successfully narrowed the types when comparing againstUNSET
.
- Change Summary:
-
Removed unused imports.
- Commits:
-
Summary ID 7c3528829b2bc7bcc600a4251419c84984d5de50 378e5a3ca00584065981c8c435d4b1e75bc3ecc0 - Diff:
-
Revision 2 (+70 -6)