On Thu, May 27, 2021 at 2:00 PM micro codery <ucod...@gmail.com> wrote:

> ...
>
By providing the name as the first argument, all
> of my examples of callables currently in the standard library will work as
> you
> say out of the box. If it were to be passed in last, this new syntax would
> not be
> usable by any standard library callable (or even third party? Does anyone
> create factory functions that need the name and take it last?) and lots of
> new
> functions would have to be added.
>
>
> Regards,
> ~Jeremiah
>

Yes that's true.

I originally wrote the proposal with the arguments switched around. But I
it seemed like it could be important to have the decorated_object argument
appear first in the signatures for both __call__ and __decoration_call__,
or it could cause confusion...

However, I am open to the idea I was right the first time.

If so, the default implementation at the top of the object food chain would
be something like (using Matt's SENTINEL idea):

def  __decoration_call__(self, by_name, obj=SENTINEL):
    if func is SENTINEL:
        return self(by_name)
    return self(obj)

On the one hand, this might be too expensive; an identity check and
potentially two function calls occur for all @ decorations. And I don't see
how to optimize this away with opcodes...

On the other hand, how often are people invoking millions of @ decorations
in a loop...?

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
_______________________________________________
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/O7TW667B7PYBOQ4M52WEXXYNQ6NZN7VM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to