B
Bror Johansson
Hi,
I have a class-hierarchy (fairly deep and fairly wide).
Is there a good and general way to test an instance-object obj for having a
class belonging to a certain "sub-tree" of the hierarchy with a common
parent class C?
Testing for presence of attributes created at __init__ time is not
considered general.
Testing presence in the set of (manually enumerated) classes belonging to
the "subtree" is not considered general.
Testing like this:
if C in [obj.__class__] + list_of_superclasses_to(obj.__class__):
...
is general but I'm looking for a better way, if there is one.
/BJ
I have a class-hierarchy (fairly deep and fairly wide).
Is there a good and general way to test an instance-object obj for having a
class belonging to a certain "sub-tree" of the hierarchy with a common
parent class C?
Testing for presence of attributes created at __init__ time is not
considered general.
Testing presence in the set of (manually enumerated) classes belonging to
the "subtree" is not considered general.
Testing like this:
if C in [obj.__class__] + list_of_superclasses_to(obj.__class__):
...
is general but I'm looking for a better way, if there is one.
/BJ