Nick Coghlan added the comment:

Right, there's a very similar instance-method-reuse related problem described 
in http://bugs.python.org/issue29270, where ctypes re-uses a class namespace is 
define a swapped-endianness version of the originally defined class.

The easiest place to deflect conflicts is at the point where bound instance 
methods are created:


>>> bound_method = MyList().insert
>>> bound_method.__self__.__class__
<class '__main__.MyList'>
>>> bound_method.__func__.__closure__[0].cell_contents
<class '__main__.MyList'>
>>> bound_method.__self__.__class__ is 
>>> bound_method.__func__.__closure__[0].cell_contents
False

However, that method of detection only works for plain instance methods that 
only close over the `__class__` variable: as soon as you wrap them in a 
decorator, you may not have easy access to the `__closure__` attribute any 
more, and if the method has closure references to more than just `__class__`, 
then it's a bit more work to find the right closure index from outside the 
function.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29944>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to