[Python-ideas] Problems (and solutions?) in writing decorators
rosuav at gmail.com
Tue Mar 19 09:41:18 EDT 2019
On Wed, Mar 20, 2019 at 12:37 AM Sylvain MARIE via Python-ideas
<python-ideas at python.org> wrote:
> > If the answer is "maybe", IMO PyPI is the right solution for distribution.
> Very wise words, I understand this point.
> However as of today it is *not* possible to write such a library in a complete way, without an additional tool from the language itself. Trust me, I tried very hard :). Indeed `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. So there is always one remaining ambiguous case to cover, and I have to rely on some ugly tricks such as asking users for a custom disambiguator.
Fair point. Though the custom disambiguator could be as simple as
using a keyword argument - "my_decorator(x=foo)" is not going to look
like "@my_decorator \n def foo".
More information about the Python-ideas