[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

type hinting backward compatibility with python 3.0 to 3.4

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.