type() new style class instance says "class", not "ObjectType"
Magnus Lie Hetland
mlh at vier.idi.ntnu.no
Wed Apr 10 22:18:12 EDT 2002
In article <3cb4bd45$1_1 at goliath.newsgroups.com>, Brad Clements wrote:
>Could someone explain this to me.
>
>Lots of code does type(x) in [InstanceType]
First solution: Don't do this. Type checking is bad.
Why do you have to do this? Could you give an example?
>One might imagine that to support new style classes, this would be changed
>to:
>
>type(x) in [InstanceType,ObjectType]
>
>
>But that doesn't work because type(new style instance) returns "Class"
>This seems the best way:
>
>>>> isinstance(y,ObjectType)
>1
>>>>
Well...
>>> isinstance(1, ObjectType)
1
Sorry :)
And in case you hadn't noticed:
>>> ObjectType is object
1
>I'm hoping someone can illucidate this for me.
What is it you want to detect with your type checking? Whether
something is an "object" or not is pretty meaningless with new-style
classes... (Everything is.)
--
Magnus Lie Hetland The Anygui Project
http://hetland.org http://anygui.org
More information about the Python-list
mailing list