I can't inherit from "compiled" classes ?

Maxim Veksler hq4ever at gmail.com
Sun Apr 29 16:27:59 EDT 2007


On 4/29/07, Marc 'BlackJack' Rintsch <bj_666 at gmx.net> wrote:
> In <mailman.7093.1177876116.32031.python-list at python.org>, Maxim Veksler
> wrote:
>
> > Hello list,
> >
> > I'm trying to subclass socket and select, for both I get:
> > """ TypeError: Error when calling the metaclass bases
> >     module.__init__() takes at most 2 arguments (3 given) """, I don't
> > understand this error. Why would python try to pass 3 arguments (what
> > are they) ?
> >
> > Googling for this error gave random results talking about try to
> > inherit a "Package" but socket is definitely a class,
> > (/usr/lib/python2.4/socket.py). Not sure about select thought.
> >
> > I've did the following to receive the error:
> > """
> > In [1]: import socket
> >
> > In [2]: class PollingSocket(socket):
> >    ...:     pass
> >    ...:
> > ---------------------------------------------------------------------------
> > exceptions.TypeError                                 Traceback (most
> > recent call last)
> >
> > /home/hq4ever/<ipython console>
> >
> > TypeError: Error when calling the metaclass bases
> >     module.__init__() takes at most 2 arguments (3 given)
> > """
> >
> >
> > What am I breaking wrong?
>
> You are trying to subclass a module here, just like the error message
> says.  The module contains a `socket` type:
>
> In [3]: import socket
>
> In [4]: type(socket)
> Out[4]: <type 'module'>
>
> In [5]: type(socket.socket)
> Out[5]: <type 'type'>
>

Great,
"""
from socket import socket
import select

class PollingSocket(socket):
   pass
"""

> `select.select()` is a function:
>
> In [6]: import select
>
> In [7]: type(select.select)
> Out[7]: <type 'builtin_function_or_method'>
>

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?

Does this mean I can't somehow make this work: """class
PollingSocket(socket.socket, select):""" ?

Thanks for the help,

> Ciao,
>         Marc 'BlackJack' Rintsch

Maxim.


-- 
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?



More information about the Python-list mailing list