> > ONE way might be to have the new method call the existing dunders. But > that's not my preference-- I would like to find another way. I do have > another idea, and I presented it in a previous response. Here it is again: > > def __key_or_index_translator__(self, pos1, pos2, *, x) -> > Tuple[Tuple[Any], Dict[str, Any]]: > """I only allow subscripting like this: > > >>> obj[1, x=2] > """ > return (pos1, pos2), dict(x=x) > > The returned two-tuple, `t`, in turn gets unpacked like for each of the > existing item dunders: > > obj.__getitem__(*t[0], **t[1]) > obj.__setitem__(value, *t[0], **t[1]) > obj.__delitem__(*t[0], **t[1]) >
Cripes, I screwed up the __key_or_index_translator__ docstring. See correction below, sorry. ------------------- def __key_or_index_translator__(self, pos1, pos2, *, x) -> Tuple[Tuple[Any], Dict[str, Any]]: """I only allow subscripting like this: >>> obj[1, 2, x=2] """ return (pos1, pos2), dict(x=x) --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/NFRYYCDWALWZE5OP3EGAIRG2ECYDI65W/ Code of Conduct: http://python.org/psf/codeofconduct/