Hi Todd
You wrote:
> Do we have an agreement on the API as Guido requested? From my
> understanding, and please correct me if I am wrong, you are still talking
> about implementing this using a new class. However, most people who
> support the use of labelled indexing.and expressed an opinion support a
> keyword argument-based approach.
>
Thank you for your prompt and close interest. For clarity, I don't think
we have agreement on the API. (While I was writing this message, Guido
posted a similar view.)
I see my kwargs package as a way of exploring the design of the API. To
help, let me give you a guided tour of some of the files in the package.
You'll find the following code
from .jfine import key_to_jfine
Point = namedtuple('Point', ('x', 'y'))
class PointMap(dict):
@key_to_jfine
def __setitem__(self, val, x, y):
pnt = Point(x, y)
dict.__setitem__(self, pnt, val)
in
https://github.com/jfine2358/python-kwkey/blob/master/kwkey/example_jfine.py
The decorator key_to_jfine comes from the kwkey.jfine submodule. It
implements the API that I favour. This is my first contribution to the
exploration of the API.
The kwkey.sdaprano implements, I believe, the API that Steven D'Aprano
favours. I believe that from this he (or anyone else such as you) can
similarly implement example_sdaprano, example_todd and so forth.
Also implemented are kwkeys.test_jfine and kwkey.test_sdaprano submodules.
Although a bit cryptic, they do show what is going on.
For example, jfine gives
# Arguments passed to setitem.
>>> d[o(1, 2, a=3, b=4)] = 'val'
(('val', 1, 2), {'a': 3, 'b': 4})
while sdaprano gives
# Arguments passed to setitem.
>>> d[o(1, 2, a=3, b=4)] = 'val'
((1, 2), 'val', {'a': 3, 'b': 4})
In case it's needed, the current tree, referred to above, is
https://github.com/jfine2358/python-kwkey/tree/81817ec01a3f0dbb46897df3f6d819a87740b295
Many thanks to Ricky Teachey, who discovered the resources above, and who
kindly wrote
I'm really interested in this and it's very helpful that you included two
> versions of the proposed API for people to try out: the jfine version (with
> the kw object) and the stevedaprano version (with kwd arguments passed
> directly to the dunder methods).
This is I think nicely explained. (Nitpick. I called it sdaprano.py, to
align with jfine.py.)
I think it would be really helpful if Steven could confirm or correct my
implementation of his proposed API. I think it would also be really helpful
to have an example that uses his API. It needn't be the same example as the
one I've written.
I hope this helps (and does no harm).
--
Jonathan
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/5D7ZANIPACRB3MO5X4KET4P7MIIE3RDJ/
Code of Conduct: http://python.org/psf/codeofconduct/