decorator with ```

R

Roman Suzi

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.

Less-decorated are also fine:

```staticmethod```
def makeDecoratorSyntax(spec=None):
raise NotImplementedException()

Several block could also concatewnate:

```staticmethod```
```decor2```
def makeDecoratorSyntax(spec=None):
raise NotImplementedException()

Or use ; to put them into one line:

```staticmethod; decor2```
def makeDecoratorSyntax(spec=None):
raise NotImplementedException()


Of course, the same could be put AFTER def, like docstring.

Sincerely yours, Roman A.Suzi
 
S

Sean Ross

Roman Suzi said:
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.
 
S

Sean Ross

[snip]
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()
[snip]

It would work something like this:

def triplebacktick(this, transform):
this.doc = transform.doc
return transform(this)

def transform(f):
""" Factory for new decorator syntaxes.

Keeps all proposals in a list and will recombine
them at random if called without a spec.
"""
f = staticmethod(f)
f.author = "somebody"
return f

def makeDecoratorSyntax(spec=None):
raise NotImplementedException()

makeDecoratorSyntax = triplebacktick(makeDecoratorSyntax, transform)
 
B

Bernhard Herzog

Roman Suzi said:
```staticmethod```
def makeDecoratorSyntax(spec=None):
raise NotImplementedException()

That's already legal Python, although it's not very useful:
.... raise NotImplementedException()
....
Bernhard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top