basedmypy
basedmypy copied to clipboard
Support asymetric type-guards with any value in the false branch
def guard(x: object) -> x is int if True else x is str: ...
def guard(x: object) -> True if True else x is str: ...
likely a subset of #235
hmm, thinking about this more maybe it doesnt make sense to support it. i cant think of a situation where it'd be correct
def foo(value: object) -> value is str if True else value is int:
"""what code could possibly go here to make this typeguard correct in both cases?"""
hmm, thinking about this more maybe it doesnt make sense to support it. i cant think of a situation where it'd be correct
def foo(value: object) -> value is str if True else value is int: """what code could possibly go here to make this typeguard correct in both cases?"""
def f(x: object):
if isinstance(x, str):
return True
if isinstance(x, int):
return False
raise Exception