Is types.InstanceType no longer valid with Python 2.2

Emile van Sebille emile at fenx.com
Thu Jan 3 10:39:28 EST 2002


"Georg Lohrer" <GeorgLohrer at gmx.de> wrote in message
news:rnq83usnib0vh8cma37kc1cufh4qbb2bvj at 4ax.com...
> Hi,
>
> after updating to Python 2.2 I've gotten some errors yielded by my
> lines:
>
> class foo:
>     pass
>
> ss = 'foo()'
> ff = eval(ss)
> assert(type(ff) == types.InstanceType)
>
> Because until version 2.1 of Python any instantiated object has its
> type 'instance', but with Python 2.2 this has been changed. Now the
> same object if for example is created dynamically with 'eval()' (in my
> case) it's a 'new-style'-class and its type-output has been changed:
>
> type(ff) = '__main__.foo'
>
> That's okay, but with my asserts I only wanted to assure that there an
> instantiated object, instead of a list or a tuple will be used!
>
> For deeper leveled classes it will look like:
>
> from BBX.Base.corbautil import ORBFacade
> orb_facade = ORBFacade()
> type(orb_facade)
>
> >>> 'BBX.Base.corbautil.ORBFacade'
>
> I don't want to add the whole nesting level of the testable object in
> an 'isinstance'-call nor can I use the assert-statement any longer.
>
> Do you know a short way to assure that the variable is an object
> independent of the class-type?
>
> Any comments and issues are appreciated.
>
> Ciao, Georg

assert isinstance(ff, foo)

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list