-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Current CL pyspecs use Python features, which are not handled by type checkers.
A notable example is usage of type expressions like List[Validator, <integer expression>]
.
With the current MyPy config, such an expressions become Any
which effectively disables type-checking. Thus, certain bugs, which in theory should be caught by type checking, are missed.
However, this cannot be fixed by just modifying the MyPy config or replacing the type checker, since type-checkers are typically not supposed to handle dependently typed expressions. See for example MyPy issue 11501 and MyPy documentation (remerkleable
's List.__class_getitem__
is implicitly invoked, when instantiating List[Validator, integer expr]
).
One way to resolve such problems is to preprocess pyspecs. E.g. one can mechanically replace expressions like List[Validator, <integer expr>]
with ListXXX[Validator]
or similar construct, which is not a dependent type anymore and can be handled by regular type checkers.
Note that one can do such preprocessing solely for type-checking purposes, e.g. the preprocessed code can be discarded after the type checking step.
NB Writing a custom MyPy plugin is not enough due to the previously mentioned __class_getitem__
problem.
There can be other Python features, whose type-checking is not directly supported, but can be handled after appropriate pre-processing.