I am using python language for Squish Automation Tool. This tool extends python with some custom objects and functions. This is what they say in the manual:
Squish's Python-specific extension modules are loaded automatically by internally executing the equivalent of the following statements:
Python import test import testData import object import objectMap import squishinfo from squish import *
This means that it is not necessary to import them yourself unless you are developing your own standalone module.
By doing so they redefine object
automatically (to this), so my attempts to do the New-Style Classes (like class NewClass(object):
) throw me an error:
TypeError: Error when calling the metaclass bases.
module.__init__()
takes at most 2 arguments (3 given)
So I'm trying to get the object
back.
After reading the amazing article about metaclasses I'm trying to get the object
with the following code:
class OrigObject:
__metaclass__ = type
class NewClass(OrigObject):
pass
My question is: is that the same as inheriting from the original object
class?
UPDATE: I'm limited to use the Python 2.4 (if that matters)
Thanks!
From the very page you linked:
Squish's object module has the same name as the base class of all Python 2 new-style classes, and of all Python 3 classes. In practice this is very rarely a problem. For Python 2 we can just create old-style classes or do
import __builtin__
and inherit from__builtin__.object
instead of object. For Python 3 there is no need to do anything since we don't ever explicitly inherit object since it is inherited by default if no other class is specified.
So:
>>> import __builtin__
>>> __builtin__.object
<type 'object'>
>>> class SomeOldStyleClass():
... pass
...
>>> SomeOldStyleClass.__subclasses__()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: class SomeOldStyleClass has no attribute '__subclasses__'
>>> class SomeClass(__builtin__.object):
... pass
...
>>> SomeClass.__subclasses__()
[]
Although, I would note that I think this is an incredibly poor decision on the part of the creators of said module, they should have called it something else. Even if it's aimed at Python 3.x, if they are distributing it for 2.x, they should have thought for a moment, it would have done them no harm to call it something else, and by calling it object
they create problems.