basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

type assertions

Open KotlinIsland opened this issue 2 years ago • 0 comments

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
    

KotlinIsland avatar Aug 27 '23 08:08 KotlinIsland