Another idea:

Instead of new dunders, have a class attribute that flags the
existing ones as taking positional and keyword arguments.

    class ILikeMyIndexesPositional:

        __newstyleindexing__ = True

        def __getitem__(self, i, j, spam = 42):
            ...

Advantages:

No new dunders or type slots required.

Disadvantages:

Code that expects to be able to delegate to another object's
item dunder methods could break. There are two ways that existing
code might perform such delegation:

    def __getitem__(self, index):
        return other_object[index]

    def __getitem__(self, index):
        return other_object.__getitem__(index)

Neither of these will work if index is a tuple and other_object
takes new-style indexes, because it will get passed as a single
argument instead of being unpacked into positional arguments.

The only reliable way to perform such delegation would be

    __newstyleindexing__ = True

    def __getitem__(self, *args, **kwds):
        return other_object[*args, **kwds]

but that requires the delegating object to be aware of
new-style indexing.

So having thought it through, I'm actually anti-proposing this
solution.

--
Greg




--
Greg
_______________________________________________
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/L3AZFU44NURH2RKIMAUKR7OTSIK5D445/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to