deleting, but not getting, slices

Phil Dumont phil at solidstatescientific.com
Mon May 16 16:53:22 EDT 2005


>>> import sys
>>> sys.version
'2.3.4 (#1, Feb  4 2005, 12:19:08) \n[GCC 3.2.3 20030502 (Red Hat Linux
3.2.3-42)]'


I'm implementing a type that supports a subset of the sequence
abstraction in which I want to allow the deletion of elements/slices,
but don't need/want to allow the fetching of a slice.  So I filled
in the tp_as_sequence slot, filled in the sq_ass_slice slot, and
did not fill in sq_slice.

I was surprised to find that this did not work.

On further investigation, I found out that it was because in
assign_slice(), the call to PySequence_(Del|Set)Slice is inside
this test:

  if (sq && sq->sq_slice && ISINT(v) && ISINT(w)) {
    ...

It baffles me why the test if for sq_slice, not sq_ass_slice,
when neither of PySequence_(Del|Set)Slice reference sq_slice,
but both reference sq_ass_slice.

My attempts to find an explanation in the docs/faqs/code have
been thusfar fruitless.

I'm able to work around it by defining a sq_slice that does
nothing but unconditionally raise an exception.  But the check
for sq_slice in assign_slice() makes me wonder if this is the
right thing to do.  (Seems ok so far.)

Any hints would be appreciated

phil





More information about the Python-list mailing list