All of your answers are true,

> (Chris)
> "my_decorator(x=foo)" is not going to look like "@my_decorator \n def foo".

That’s one of the many ways that `decopatch` uses to perform the 
disambiguation, indeed. But that’s already the user helping the lib, not the 
other way round

> (Christopher)
> @something applied on def fun is exactly the same as something(fun)

True. However applying decorator manually is already for advanced users, so 
users of a decopatche-d decorator will not mind calling something()(fun). In 
fact it is consistent with when they use it with arguments : 
something(arg)(fun).

Another criterion is : how easy would it be to implement an 
inspect.is_decorator_call(frame) method returning True if and only if frame is 
the @ statement ? If that’s fairly easy, well, I’m pretty sure that this is 
good stuff. From a naïve user, not accustomed with the long history of this 
language, is very strange that an operator such as @ (the decorator one, not 
the other one) is completely not detectable by code, while there are so many 
hooks available in python for all other operators (+, -, etc.).

Eventually that’s obviously your call, I’m just there to give feedback from 
what I see of the python libs development community.

--
Sylvain

De : Python-ideas <python-ideas-bounces+sylvain.marie=se....@python.org> De la 
part de Christopher Barker
Envoyé : mercredi 20 mars 2019 06:50
À : Greg Ewing <greg.ew...@canterbury.ac.nz>
Cc : python-ideas <python-ideas@python.org>
Objet : Re: [Python-ideas] Problems (and solutions?) in writing decorators


[External email: Use caution with links and attachments]

________________________________


Also:

@something
def fun():
...

Is exactly the same as:

def fun()
...

fun = something(fun)

So you can’t make a distinction based whether a given usage  is as a decoration.

-CHB

On Tue, Mar 19, 2019 at 12:26 PM Greg Ewing 
<greg.ew...@canterbury.ac.nz<mailto:greg.ew...@canterbury.ac.nz>> wrote:
Sylvain MARIE via Python-ideas wrote:
> `my_decorator(foo)` when foo is a callable will always look like
> `@my_decorator` applied to function foo, because that's how the language is
> designed.

I don't think it's worth doing anything to change that. Everywhere
else in the language, there's a very clear distinction between
'foo' and 'foo()', and you confuse them at your peril. I don't see
why decorators should be any different.

--
Greg
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org<mailto:Python-ideas@python.org>
https://mail.python.org/mailman/listinfo/python-ideas<https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas&data=02%7C01%7Csylvain.marie%40se.com%7C2e9308c9904c40f3702408d6acf7fc3a%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C0%7C636886578423739625&sdata=%2BSHOm4PYwt6p%2F6Of69z0o19sH%2FimE4YsUFFtaEMlYCc%3D&reserved=0>
Code of Conduct: 
http://python.org/psf/codeofconduct/<https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F&data=02%7C01%7Csylvain.marie%40se.com%7C2e9308c9904c40f3702408d6acf7fc3a%7C6e51e1adc54b4b39b5980ffe9ae68fef%7C0%7C0%7C636886578423739625&sdata=uO%2Bq8AahHYhCVObE%2Fq3Tn%2BODC0vsdjWfX2niuuNgemE%3D&reserved=0>
--
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
______________________________________________________________________
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to