On Sonntag 04 Januar 2009, Hans Meine wrote: > I have exported an array-like class using the __getitem__ implementation > given below among its overloads. It uses > boost::python::slice.get_indices(), and I am getting a RuntimeError when I > try to acces e.g. [1:-1] on a 2-element array. What is the rationale for > this "Zero-length slice" error? I would expect an empty iterator range. > OK, if end < begin, that could make problems, but what am I expected to do > to prevent this RuntimeError? (Yes, I did RTFM, but maybe I am overlooking > something?)
Yes, I was overlooking quite some things. Quoting the docs: > Rationale: [...] > exceptions on empty slice: It is impossible to define a closed interval > over an empty range, so some other form of error checking would have to be > used to prevent undefined behavior. In the case where the exception is not > caught, it will simply be translated to Python by the default exception > handling mechanisms. I was tired and the automatic translation of std::invalid_argument into a RuntimeError obviously outsmarted me. So obviously, the answer is that I have to copy the boilerplate-try..catch from the docs (and handle the empty interval case). Ciao, / / .o. /--/ ..o / / ANS ooo
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig