python Yes typing hint !
def upload(content: str) -> bool:
pass
however content Can pass any type , such as str、bytes、int、float wait
therefore , I will do this :
def upload(content: str) -> bool:
assert isinstance(content, str) #
pass
It can solve the problem of type verification ! But this is very inelegant ! Because every function has to add assert, The code will become very ugly and redundant !
So I want cpython Add a grammar sugar
def upload(content:: str) -> bool:
pass
hold typing hint Single colon of :
Change to double colon ::
Double colon ::
It means automatically according to the following typing hint Do type verification !
A single colon indicates pure typing hint
Double colons indicate typing hint + check type
I think this is a great grammar candy , What should I do to make cpython
Those people who 100% Realize this new function ?
Give Way python Great again