new-style class instance check (bis)

R

Richard Gruet

(just a reformulation of my previous post)

How to determine that an object o is for sure an instance of a new-style
class, without knowing of which specific class ?
That is, if I define a function:

def isNewStyleClassInstance(o):
pass ## to be completed

... I want to pass the following test:

class OldStyle: pass
class NewStyle(object): pass

assert not isNewStyleClassInstance(OldStyle()) # InstanceType
assert isNewStyleClassInstance(NewStyle())
assert not isNewStyleClassInstance('hi') # "instance" of type str

# and naturally for all other types of o the function should also return
False, e.g.

def foo(): pass
assert not isNewStyleClassInstance(foo) # FunctionType
assert not isNewStyleClassInstance(OldStyle) # ClassType
# etc...


Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top