I can't inherit from "compiled" classes ?

Diez B. Roggisch deets at nospam.web.de
Mon Apr 30 07:46:28 EDT 2007


> I understand what you are saying, and at the same time don't
> understand why it doesn't work. Isn't "everything an object" in
> python? And if something is an object does it not implies it's an
> instance of some class?

It means that, but it seems that you can't subclass everything, especially
functions:

>>> ft = type(lambda x: x)
>>> ft
<type 'function'>
>>> class FunctionSubclass(ft): pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: Error when calling the metaclass bases
    type 'function' is not an acceptable base type
>>>                                    

But even _if_ you could - what good does it do to you? select being an
_instance_ of function, it doesn't help you anything to subclass from it's
class. This doesn't affect select itself, in the same sense that instances
of some class Foo aren't affected by a subclass Bar(Foo).

Besides that, the semantics of "subclassing" a function type are unclear.
What would you expect?
 
> Does this mean I can't somehow make this work: """class
> PollingSocket(socket.socket, select):""" ?

As I point out above, this is a non-sensical thing to do anyway. Maybe you
should tell us what you want to accomplish here?

Diez



More information about the Python-list mailing list