On 2/2/21 12:36 PM, Stefano Borini wrote:
Hi all,
I would like to request feedback by python-dev on the current
implementation of PEP 637 - Support for indexing with keyword
arguments.
https://www.python.org/dev/peps/pep-0637/
The PEP is ready for SC submission and it has a prototype
implementation ready, available here (note, not reviewed, but
apparently fully functional)
https://github.com/python/cpython/compare/master...stefanoborini:PEP-637-implementation-attempt-2
(note: not sure if there's a preference for the link to be to the diff
or to the branch, let me know if you prefer I change the PEP link)
Thank you for your help.
+1 from me. This looks quite useful in certain areas and natural to use.
I like how this makes the dunder implementations (usually libraries),
rather than users, deal with most of the corner cases -- but still
allows libraries that don't need this to not care.
The PEP does lack a "How to teach" section.
"Corner case 3" concludes that "best practice suggests that keyword
subscripts should be flagged as keyword-only when possible":
def __getitem__(self, index, *, direction='north'):
If the PEP is accepted, this should be mentioned in the
__(get|set|del)item__ documentation and shown in all relevant examples.
Looking at corner case 1, it would also be useful to nudge people to use
positional-only arguments whenever they accept arbitrary keyword ones.
(The same goes for function definitions, but tutorials for those are
already written):
def __getitem__(self, index, /, **named_axes):
It would be great if what gets copied to StackOverflow is examples of
good practices :)
_______________________________________________
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/2CN5A7JTZUCXTP6OMPAXWH2ABOPX6SIS/
Code of Conduct: http://python.org/psf/codeofconduct/