I can't inherit from "compiled" classes ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maxim Veksler

    I can't inherit from "compiled" classes ?

    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(s ocket):
    ...: pass
    ...:
    ---------------------------------------------------------------------------
    exceptions.Type Error 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?

    Thank you,
    Maxim.

    --
    Cheers,
    Maxim Veksler

    "Free as in Freedom" - Do u GNU ?
  • half.italian@gmail.com

    #2
    Re: I can't inherit from &quot;compiled& quot; classes ?

    On Apr 29, 12:48 pm, "Maxim Veksler" <hq4e...@gmail. comwrote:
    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(s ocket):
    ...: pass
    ...:
    ---------------------------------------------------------------------------
    exceptions.Type Error 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?
    >
    Thank you,
    Maxim.
    >
    --
    Cheers,
    Maxim Veksler
    >
    "Free as in Freedom" - Do u GNU ?
    Try:

    import socket

    class PollingSocket(s ocket.socket):
    pass

    ~Sean

    Comment

    • Marc 'BlackJack' Rintsch

      #3
      Re: I can't inherit from &quot;compiled& quot; classes ?

      In <mailman.7093.1 177876116.32031 .python-list@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(s ocket):
      ...: pass
      ...:
      ---------------------------------------------------------------------------
      exceptions.Type Error 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.soc ket)
      Out[5]: <type 'type'>

      `select.select( )` is a function:

      In [6]: import select

      In [7]: type(select.sel ect)
      Out[7]: <type 'builtin_functi on_or_method'>

      Ciao,
      Marc 'BlackJack' Rintsch

      Comment

      • Maxim Veksler

        #4
        Re: I can't inherit from &quot;compiled& quot; classes ?

        On 4/29/07, Marc 'BlackJack' Rintsch <bj_666@gmx.net wrote:
        In <mailman.7093.1 177876116.32031 .python-list@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(s ocket):
        ...: pass
        ...:
        ---------------------------------------------------------------------------
        exceptions.Type Error 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.soc ket)
        Out[5]: <type 'type'>
        >
        Great,
        """
        from socket import socket
        import select

        class PollingSocket(s ocket):
        pass
        """
        `select.select( )` is a function:
        >
        In [6]: import select
        >
        In [7]: type(select.sel ect)
        Out[7]: <type 'builtin_functi on_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(s ocket.socket, select):""" ?

        Thanks for the help,
        Ciao,
        Marc 'BlackJack' Rintsch
        Maxim.


        --
        Cheers,
        Maxim Veksler

        "Free as in Freedom" - Do u GNU ?

        Comment

        • Gabriel Genellina

          #5
          Re: I can't inherit from &quot;compiled& quot; classes ?

          En Sun, 29 Apr 2007 17:27:59 -0300, Maxim Veksler <hq4ever@gmail. com>
          escribió:
          On 4/29/07, Marc 'BlackJack' Rintsch <bj_666@gmx.net wrote:
          >>
          """
          from socket import socket
          import select
          >
          class PollingSocket(s ocket):
          pass
          """
          >
          >`select.select ()` is a function:
          >
          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?
          I'm not sure if your last statement is true now, and certainly it was not
          true before Python 2.2; there were objects that were not class instances
          (numbers, functions, by example). Maybe some objects still remain that are
          not instances of any class.
          Anyway, "an object" and "a class" are not the same thing, and you can't
          use an arbitrary object when you actually need a class.
          Does this mean I can't somehow make this work: """class
          PollingSocket(s ocket.socket, select):""" ?
          Those things inside () are called "base classes"; this is "class"
          inheritance; you create a new "class" inheriting from existing ones. That
          is, you cant inherit from select, because select is a function, not a
          class.

          --
          Gabriel Genellina

          Comment

          • Diez B. Roggisch

            #6
            Re: I can't inherit from &quot;compiled& quot; classes ?

            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 FunctionSubclas s(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 "subclassin g" a function type are unclear.
            What would you expect?
            Does this mean I can't somehow make this work: """class
            PollingSocket(s ocket.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

            Comment

            Working...