473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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(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?

Thank you,
Maxim.

--
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?
Apr 29 '07 #1
5 2104
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(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?

Thank you,
Maxim.

--
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?
Try:

import socket

class PollingSocket(socket.socket):
pass

~Sean

Apr 29 '07 #2
In <ma***************************************@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'>

`select.select()` is a function:

In [6]: import select

In [7]: type(select.select)
Out[7]: <type 'builtin_function_or_method'>

Ciao,
Marc 'BlackJack' Rintsch
Apr 29 '07 #3
On 4/29/07, Marc 'BlackJack' Rintsch <bj****@gmx.netwrote:
In <ma***************************************@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 ?
Apr 29 '07 #4
En Sun, 29 Apr 2007 17:27:59 -0300, Maxim Veksler <hq*****@gmail.com>
escribió:
On 4/29/07, Marc 'BlackJack' Rintsch <bj****@gmx.netwrote:
>>
"""
from socket import socket
import select

class PollingSocket(socket):
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(socket.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
Apr 29 '07 #5
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
Apr 30 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rick | last post by:
Hello all. I have an index.php file that has a lot of functions that I wrote. Let's say for the sake of argument that there are 1000 functions of 100 lines each. The index.php file is invoked...
0
by: polite person | last post by:
This post comes from seeing the protracted thread(s) on use of integer v long in loop code. My first reaction was "why not print out the "compiled" code and see what it is in each case? That should...
7
by: Matt Jensen | last post by:
Howdy I want to simulate with .Net what I used to do with classic ASP where you would have a series of include files with utility functions that you would include when you needed them. I read...
10
by: ptass | last post by:
Hi In asp.net 2.0 an aspx files .cs file is a partial class and all works fine, however, I thought I’d be able to create another class file, call it a partial class and have that compile and...
7
by: relient | last post by:
Question: Why can't you access a private inherited field from a base class in a derived class? I have a *theory* of how this works, of which, I'm not completely sure of but makes logical sense to...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
1
by: BigDave | last post by:
Hi all, We have the desire to improve the "first hit lag" issue our their still low-volume asp.net 2.0 site. I maintain that the app is being unloaded from IIS 6 due to idleness. However, our...
2
by: Okko Willeboordse | last post by:
To get the "code object" c of my_class I can do; c = compile(inspect.getsource(my_class), "<script>", "exec") This fails when inspect can't get hold of the source of my_class, for instance...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.