Hi all,

Annotations of function parameters and variables are evaluated when
encountered. This makes it necessary to use string representation for names
that are not yet bound, which affects almost every class definition. It is
also easy to forget, and the result might be a (very uninteresting)
exception in certain untested paths, e.g. inside functions. Editors and
IDEs also don't handle it well; for example, PyDev does not consider
string-annotations as an occurrence of the name, and warns about unused

I propose delaying evaluation of annotation-expressions by either keeping
the AST of the annotation, or turning it implicitly from EXP into "lambda:
EXP". Inspection code that is interested in this information can access it
be calling (or evaluating) it.

It certainly isn't a backward compatible change, but I think it won't
affect too much code. On the positive side, it will make annotated code
much more pleasing to read, will be less surprising for beginners, and will
help editors in syntax highlighting and name lookup.

In short, it will shift the burden of handling type annotations from
standard code to inspection code, which is where I believe it should rest.

While this idea is quite obvious, I've found no clue in PEP-3107 as to why
will it be a bad one (no such "rejected proposal" there), so I raise the
question here.

Python-ideas mailing list
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to