On Wed, Aug 05, 2020 at 03:35:15PM +0200, Marco Sulla wrote:

[Greg Ewing]
> > > A considerable number of moons ago, I suggested that
> > >
> > >     @my_property
> > >     fred = 42
> > >
> > > should expand to
> > >
> > >     fred = my_property("fred", 42)
> > >
> > > The point being to give the descriptor access to the name of
> > > the attribute, without having to repeat yourself.


[Dominik Vilsmeier]:
> > That should be possible by doing `fred = my_property(42)` and defining
> > `__set_name__` on the `my_property` class.

Just because you define your own dunder method (which you shouldn't do, 
since dunders are reserved for the interpreter's use) doesn't make 
something which is a syntax error stop being a syntax error.


[Marco Sulla]
> I suppose that what Greg Ewing suggests is a way to define a sort of
> custom simple statement.
> 
> For example, instead of the old
> print "Hello"
> 
> and the "new"
> print("Hello")
> 
> you could write
> 
> @print
> "Hello"

Perhaps you should re-read Greg's proposal again. I've left it quoted 
above. This is a proposal for decorator syntax, not a new way to call 
objects for their side-effects. If there's no assignment, it isn't going 
to work, it's still going to be a syntax error.

This would work:

    @print
    word = "Hello"

but it would print "word Hello", and assign None to `word`.

So no, Greg's proposal is nothing like a "custom simple statement", it 
is a proposal for an extension of decorator syntax to simple 
assignments. Your version would be a syntax error, because there is no 
assignment and no target name.


-- 
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EAK4CMCRHMM4RTAE5YKRSW6ABLBGM2CI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to