It seems very obvious to me that kwd args only should be valid, as Greg Ewing said, if kwd args are added.
I'm less sure about no arguments, but perhaps.
On Fri, Aug 14, 2020, 8:11 AM Jonathan Fine email@example.com wrote:
Storing function call results would be a use case. For this, look at the implementation of functools.lru_cache.
So maybe something like this?:
from functools important storagefunc
@storagefunc def fibonacci(*, n): return fibonacci[n=n-1]+fibonacci[n=n-2]
fibonacci[n=1] = 0 fibonacci[n=2] = 1 fibonacci[n=4]
Of course this example function may not absolutely require kwd only args but any other example that can be contrived probably doesn't absolutely require them either.
For a specific example, a simple ad hoc way of recording data. For example
>>> height[x=10, y=14] = 2010
We can already use dictionaries in this way, as in >>> height[10, 14] = 2010
So this is a bit like using named tuples instead of tuples.
This seems like another nice usage to me. But isn't it important to identify what the underlying storage is, and the rest of the API, before I would want to use something like this? After all I can do these with both a list and dictionary:
But the one I want to use is determined somewhat by what else I intend to do with it, and how it behaves under the hood... Use a ictionary for very fast item access, for example. List or tuple for ordered things.