feat(checker): statically evaluate casts to Any and None
This commit is contained in:
@@ -28,6 +28,7 @@ from midas.checker.types import (
|
|||||||
DerivedType,
|
DerivedType,
|
||||||
Function,
|
Function,
|
||||||
GenericType,
|
GenericType,
|
||||||
|
TopType,
|
||||||
TupleType,
|
TupleType,
|
||||||
Type,
|
Type,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
@@ -967,6 +968,17 @@ class PythonTyper(
|
|||||||
self, expr: p.CastExpr, subject_type: Type, target_type: Type, lit_value: Any
|
self, expr: p.CastExpr, subject_type: Type, target_type: Type, lit_value: Any
|
||||||
) -> bool:
|
) -> bool:
|
||||||
match target_type:
|
match target_type:
|
||||||
|
case TopType():
|
||||||
|
return True
|
||||||
|
|
||||||
|
case UnitType():
|
||||||
|
if lit_value is not None:
|
||||||
|
self.reporter.error(
|
||||||
|
expr.location, f"Value {lit_value!r} is not None"
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
case DerivedType(type=base):
|
case DerivedType(type=base):
|
||||||
return self._evaluate_cast_statically(
|
return self._evaluate_cast_statically(
|
||||||
expr, subject_type, base, lit_value
|
expr, subject_type, base, lit_value
|
||||||
|
|||||||
Reference in New Issue
Block a user