decorator with ```

Sean Ross sross at connectmail.carleton.ca
Thu Aug 12 07:32:14 EDT 2004


"Roman Suzi" <rnd at onego.ru> wrote in message
news:mailman.1555.1092303160.5135.python-list at python.org...
>
> One more crazy syntax before-def but which could be treated
> more generally:
>
> ```"""  Factory for new decorator syntaxes.
>
>          Keeps all proposals in a list and will recombine
>          them at random if called without a spec. """
>    staticmethod```
> def makeDecoratorSyntax(spec=None):
>     raise NotImplementedException()
>
> New execution block type (in addition to exec, eval and
> interactive) could be added to allow needed behaviour.
>
[snip]

I think it would be interesting if triple-back-ticks could be used to
introduce a kind of meta-scope, using 'this' to refer to the namespace being
operated upon (so you wouldn't have to spell out the object's name all the
time). For example:


def makeDecoratorSyntax(spec=None):
    ```"""  Factory for new decorator syntaxes.

         Keeps all proposals in a list and will recombine
          them at random if called without a spec.
        """
    this = staticmethod(this)      # <- transformation explicit
    this.author = "somebody"    # <- add attributes normally
    ```
    raise NotImplementedException()

This idea could be used to do transformations on classes and modules as
well.






More information about the Python-list mailing list