Continued New Indexing Methods Revival #N (subclasses!)
Hi all, from the discussion, I was thinking maybe something like this: class B(): def __numpy_getitem__(self, index, indexing_method="plain"): # do magic. return super().__numpy_getitem__( index, indexing_method=indexing_method) as new API. There are some issues, though. An old subclass may define `__getitem__`. Now the behaviour that would seem nice to me is: 1. No new attribute (no `__numpy_getitem__`) and also no `__getitem__`/`__setitem__`: Should just work 2. No new attribute but old attributes defined: Should at least give a warning (or an error) when using the new attributes, since the behaviour might buggy. 3. `__numpy_getitem__` defined: Will channel all indexing through it (except maybe some edge cases in python 2). Best, also avoid that use getitem in setitem trick.... If you define both (which might make sense for some edge case stuff), you should just channel it through this yourself. Now the issue I have is that for 1. and 2. to work correctly, I need to know which methods are overloaded by the subclass. Checking is a bit tedious and the method I hacked first for getitem and setitem does not work for a normal method. Can anyone think of a nicer way to do this trick that does not require quite as much hackery. Or is there an easy way to do the overloading check?  Sebastian
On Sa, 20160910 at 12:01 +0200, Sebastian Berg wrote:
Hi all,
from the discussion, I was thinking maybe something like this:
class B(): def __numpy_getitem__(self, index, indexing_method="plain"): # do magic. return super().__numpy_getitem__( index, indexing_method=indexing_method)
as new API. There are some issues, though. An old subclass may define `__getitem__`. Now the behaviour that would seem nice to me is:
1. No new attribute (no `__numpy_getitem__`) and also no `__getitem__`/`__setitem__`: Should just work 2. No new attribute but old attributes defined: Should at least give a warning (or an error) when using the new attributes, since the behaviour might buggy. 3. `__numpy_getitem__` defined: Will channel all indexing through it (except maybe some edge cases in python 2). Best, also avoid that use getitem in setitem trick.... If you define both (which might make sense for some edge case stuff), you should just channel it through this yourself.
Maybe in shorter; I would like to know if a subclass: 1. requires no fixup 2. may need fixup 3. supports everything. And I am not sure how to approach this.
Now the issue I have is that for 1. and 2. to work correctly, I need to know which methods are overloaded by the subclass. Checking is a bit tedious and the method I hacked first for getitem and setitem does not work for a normal method.
Can anyone think of a nicer way to do this trick that does not require quite as much hackery. Or is there an easy way to do the overloading check?
 Sebastian
_______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpydiscussion
participants (1)

Sebastian Berg