[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-26 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-26 Thread Raymond Hettinger


Raymond Hettinger  added the comment:


New changeset b821868e6d909f4805499db519ebc2cdc01cf611 by Raymond Hettinger in 
branch 'master':
bpo-36772 Allow lru_cache to be used as decorator without making a function 
call (GH-13048)
https://github.com/python/cpython/commit/b821868e6d909f4805499db519ebc2cdc01cf611


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-06 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

I am +1 to this. Making it easier for the case of decorator factories that are 
called with all the defaults is a very common pattern in the wild. There are 
even known idioms for how to reduce the indentation of the naive approach 
(returning partials of the factory). In particular for lru_cache, my experience 
is that every time I teach this feature, people are confused initially about 
the '()' at the end of the call.

--
nosy: +pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-05 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

To clarify, I am not opposing this feature. I had doubts because if the memory 
does not betray me similar propositions for lru_cache or other decorator 
fabrics were rejected in past. But times change.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-04 Thread Eric Snow


Eric Snow  added the comment:

As to the issue of positional vs. keyword arguments, keyword arguments make the 
implementation easier in some cases.  Otherwise I haven't seen positional 
arguments cause much of a problem.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-04 Thread Eric Snow


Eric Snow  added the comment:

FWIW, I've followed this pattern (one function is both decorator and factory) 
in my own code for quite a while.  I've never found it confusing nor has anyone 
else (that I'm aware) that has used those decorators.

One reason I've done decorators this way is because the empty parentheses are a 
visual distraction to readers.  They also imply to readers that more is going 
on than really is.  So I'm in favor of Raymond's plan.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-02 Thread Guido van Rossum


Change by Guido van Rossum :


--
nosy:  -gvanrossum

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-02 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

At Pycon today, I mostly got all positive feedback on this.  Apparently py.test 
already follows this pattern.  Another developer said they found the () to be 
distracting and would welcome not having to use them.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-02 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
nosy: +dino.viehland, eric.snow, giampaolo.rodola, njs

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-02 Thread Stefan Behnel


Stefan Behnel  added the comment:

I'm generally ok with such APIs. It seems needless to require

  @lru_cache()
  def f(): ...

when a simple decorator would suffice. I think I might decide otherwise in 
cases where almost all usages require arguments, but if the no-arguments case 
is common (and there is no ambiguity in the arguments), then I prefer not 
requiring parentheses.

--
nosy: +scoder

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-02 Thread Eric V. Smith


Eric V. Smith  added the comment:

The 90% use case with dataclasses is satisfied with just "@dataclass", and 
perhaps the target user there is less sophisticated.

But the main difference between @dataclass and @lru_cache is that all of the 
parameters to @dataclass are keyword-only. Which I did because they are mostly 
all booleans, and "@dataclass(True, False, True)" isn't very helpful.

That's not the case with @lru_cache. Whether that makes a difference for this 
issue in particular, I'm not sure.

I agree that this violates "only one way to do it". But I haven't seen anyone 
use "@dataclass()", and I've also never seen anyone be confused by the fact 
that once you want parameters, you change to using parens. For the dataclass 
case, I think that working both ways has been helpful.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-01 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

I do not like mixing decorators and decorator fabrics. But this can of worms 
has already been open by dataclasses. The question is whether we want to extend 
this design to the rest of the stdlib. lru_cache() resisted this change for a 
long time.

--
nosy: +gvanrossum

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-01 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
keywords: +patch
pull_requests: +12967
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36772] Let lru_cache be used as a decorator with no arguments

2019-05-01 Thread Raymond Hettinger


New submission from Raymond Hettinger :

Follow the lead of the dataclasses module and allow lru_cache() to be used as a 
straight decorator rather than as a function that returns a decorator.  Both of 
these would now be supported:

@lru_cache
def f(x):
...

@lru_cache(maxsize=256)
def f(x):
...

--
components: Library (Lib)
messages: 341239
nosy: eric.smith, rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Let lru_cache be used as a decorator with no arguments
type: behavior
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com