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