Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

type 'slice' is not an acceptable base type

1 view
Skip to first unread message

Antoon Pardon

unread,
Dec 20, 2005, 5:44:15 AM12/20/05
to
That was the message I received when I imported a self
written module. All I wanted to do was experiment with
subclassing slice. So I write something like:

class iterslice(slice):
...


And when I fired up the python interpreter

>>> from vslice import *
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "vslice.py", line 48, in ?
class iterslice(slice):
TypeError: Error when calling the metaclass bases
type 'slice' is not an acceptable base type


So what is going on. I thought the class vs type
distinction was eliminated in order to be able
to subclass base types. So why doesn't this work?

--
Antoon Pardon

Michael Hoffman

unread,
Dec 20, 2005, 10:47:16 PM12/20/05
to
Antoon Pardon wrote:

> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "vslice.py", line 48, in ?
> class iterslice(slice):
> TypeError: Error when calling the metaclass bases
> type 'slice' is not an acceptable base type

Searching for "not an acceptable base type" in the Python source reveals
that this exception is produced when the proposed base type doesn't have
Py_TPFLAGS_BASETYPE set.

> So what is going on. I thought the class vs type
> distinction was eliminated in order to be able
> to subclass base types. So why doesn't this work?

slice.__base__ == object. It's the basetype flag issue. You could
propose a patch to make it subclassable.
--
Michael Hoffman

Antoon Pardon

unread,
Dec 21, 2005, 4:36:21 AM12/21/05
to
Op 2005-12-21, Michael Hoffman schreef <cam....@mh391.invalid>:

I'll keep this is mind. It'll have to wait for after the holidays
though.

--
Antoon Pardon

0 new messages