Wow this is cool! Haven’t seen this function before - you’re right it does provide the same utility. I suppose the only point remaining is brevity - the !
syntax I describe is quite a bit shorter than using this typing function, and also would come as a built-in - so no need for the import at the top. That said, with a short choice of import name it can be quite brief:
from typing import assert_type as at
# here let's assume get_list comes from an external library
def get_list():
r = random.uniform(1)
if r <=0.5:
return list(['test2', 'test3'])
else:
return []
if at(get_list(), list[str]):
print('here')
In some way I suppose python progressed from the Union syntax, to using | - similarly perhaps there is some way assert_type could have a syntax upgrade