[issue18275] Make isinstance() work with super type instances
Raymond Hettinger
report at bugs.python.org
Sat Jun 22 00:22:49 CEST 2013
Raymond Hettinger added the comment:
> I have no idea what CLOS does in this situation.
No worries, I was just curious whether you knew whether this was a solved problem in Dylan or CLOS or some other language.
When faced with a diamond diagram, what are the semantics for isinstance(super_instance, cls)?
I worked on it for a little bit and came up with the following:
def super_isinstance(super_inst, cls):
'Is the cls in the mro somewhere after the current class?'
mro = super_inst.__self__.__class__.__mro__
thisclass = super_inst.__thisclass__
return cls in mro and mro.index(thisclass) < mro.index(cls)
----------
Added file: http://bugs.python.org/file30663/simple_diamond_example.py
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18275>
_______________________________________
More information about the Python-bugs-list
mailing list