[Python-Dev] The Need for a Declarative Syntax Element (aka

Jewett, Jim J jim.jewett at eds.com
Mon Apr 5 11:40:14 EDT 2004

Mike Pall:

>	It is unclear whether we have any use case that 
>	requires storing a different name ...

When adapting another module or library, it is often 
desirable to expose both the original name (for people
familiar with the original) and a cleaned up name (so
that your module can be used with internally consistent 

The current syntax is to bind a second name to the 
object after it is defined; that second binding could 
reasonably move into a decorator.  Ensuring that it 
points to a final-enough version of the object is
probably the programmer's responsibility.

>	Using __declare__

[See the original for more detail - basically, decorators
 must have a __declare__ slot which will be called.]

I think this is the first non-arbitrary restriction we have
seen on decorators.  It does largely solve the old-code-
might-run-differently issue, though not the old-interpreters-
might-silently-run-code-undecorated issue.

Your suggested markers of [| |] or <| |> also solve that,
as would a new keyword.  A new word has the advantage of
stating explicitly what it means, which allows additional
extensions (some of which you already suggested).

Defining a decorator API also allows more freedom for the
decorators; the __declare__ API could accept more than 
just the target object.  For example, it could take keywords 
giving the dictionary where the object will eventually be 
defined, or the name that will be used.  (These would reduce 
the need for _getframe.)


More information about the Python-Dev mailing list