basedmypy
basedmypy copied to clipboard
type assertions
def f(x: object) -> TypeAssertion[int]: # demarcation is tentative, maybe `Asserts[x is int]`
assert isinstance(x, int)
a: object
f(a)
reveal_type(a) # int is
Notes:
- Would want to be able to provide an assertion and a return type
def f(x: object) -> Asserts[x is int] & str: ... - Would want to be able to do 'truthy' assertions / invariants
def asserts(x: object) -> Asserts[x] ... a: object asserts(isinstance(a, bool)) reveal_type(a) # bool