[Python-3000] Draft pre-PEP: function annotations

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Aug 15 04:49:42 CEST 2006

Phillip J. Eby wrote:

> How is such a thing going to know what doc("foo") means at the time the 
> code is run?  What about closures, dynamic imports, etc.?

Annotations intended for such external processors would
have to be designed not to rely on anything dynamic,
i.e. be purely declarative.

Maybe this is why we're having trouble communicating.
You seem to be thinking of annotations purely as
dynamic things that affect the execution of the
program. I'm thinking of them as something that will
just as likely be used in a declarative way, possibly
by tools that don't execute the code at all, but do
something entirely different with it.

> Weak imports are a good solution for the case where interop is 
> optional.  You do something like:
>     @whenImported('some.doc.processor')
>     def registerDocHandler(processor):
>         @processor.someOverloadedFunction.when(SomeType)
>         def handleTypeDefinedByThisModule(...):
>             ...

But this requires the module using the annotations to
anticipate all the processors that will potentially
process its annotations, and teach each one of them
about itself.

 > Also, other people can of course define their own third-party
> glue modules that provide this kind of support for some given 
> combination of annotation types and processors.

I don't see how a third party can do this, because only the
module containing the annotations can know what idiosynchratic
scheme it's chosen for combining them.



More information about the Python-3000 mailing list