type hinting backward compatibility with python 3.0 to 3.4

Gregory Ewing greg.ewing at canterbury.ac.nz
Sat May 20 10:14:51 EDT 2017


Steve D'Aprano wrote:
> You mean treat them as syntactically comments?
> 
> def function(arg:I can put ***ANYTHING*** I like here!!!):

They could be parsed as expressions and stored as an AST.
That would allow introspection, and you could evaluate them
if you wanted

> Ever since they were introduced, annotations have always been evaluated and
> recorded in the function.__annotations__ attribute.

Yes, but I'm not sure how much good that does you. Because
of the forward-reference thing, you need to be prepared to
get a string instead of a type object, in which case you
need to do some evaluation on it yourself anyway.

-- 
Greg



More information about the Python-list mailing list