On 27Apr2020 2311, Tom Forbes wrote:
Why not? It's a decorator, isn't it? Just make it check for number of arguments at decoration time and return a different object.

It’s not that it’s impossible, but I didn’t think the current implementation doesn’t make it easy

This is the line I'd change: https://github.com/python/cpython/blob/cecf049673da6a24435acd1a6a3b34472b323c97/Lib/functools.py#L763

At this point, you could inspect the user_function object and choose a different wrapper than _lru_cache_wrapper if it takes zero arguments. Though you'd likely still end up with a lot of the code being replicated.

You're probably right to go for the C implementation. If the Python implementation is correct, then best to leave the inefficiencies there and improve the already-fast version.

Looking at https://github.com/python/cpython/blob/master/Modules/_functoolsmodule.c it seems the fast path for no arguments could be slightly improved, but it doesn't look like it'd be much. (I'm deliberately not saying how I'd improve it in case you want to do it anyway as a learning exercise, and because I could be wrong :) )

Equally hard to say how much more efficient a new API would be, so unless it's written already and you have benchmarks, that's probably not the line of reasoning to use. An argument that people regularly get this wrong and can't easily get it right with what's already there is most compelling - see the recent removeprefix/removesuffix discussions if you haven't.

Cheers,
Steve
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/HTOONP2GW3WCMWHEKHOBWNGJUYGUCACS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to