Static evalution of casts on literals #20
Reference in New Issue
Block a user
Delete Branch "feat/literal-static-constraints"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR enables the Python type checker to statically evaluate cast expressions on literal values.
To do so, it adds an
Evaluatorclass which can evaluate custom Python AST expressions given some literal value.That could have also been implemented using Python's own
evalmachinery, but I prefer to have control on how things are evaluated and what is available in the context.Finally, cast expressions which have been fully evaluated statically do not generate runtime assertions as this would be redundant.