Hi! On Thu, Apr 06, 2017 at 12:24:47PM +1000, Steven D'Aprano <steve at pearwood.info> wrote: > On Thu, Apr 06, 2017 at 02:30:06AM +0200, Oleg Broytman wrote: > > > I spent few days hunting > > for a subtle bug caused by absent of unbound methods. > > Painful. :-( > > I'm curious about this. What do you mean? Python 3 has unbound methods, > they're just the original, unwrapped function: > > py> class K: > ... def method(self, arg): > ... pass > ... > py> K.method > <function K.method at 0xb7cbd6a4> I know. > The only(?) functional difference between unbound methods in Python 2 > versus 3 is that in Python 2 they automatically do a type-check that > `self` is an instance of the class. The check was involved, yes. The bug I was hunting manifested itself in PY3 with exceptions hinting that instead of `self` I've passed `self.__class__`. In PY2 everything worked fine. I found the problem in dynamically created methods. Someone implemented them this way: if PY2: def createMethod(func, cls): return types.MethodType(func, None, cls) else: def createMethod(func, cls): return types.MethodType(func, None) Hard to spot at the first glance what was the problem. Finally I grok the problem and fixed the implementation for PY3 to def createMethod(func, cls): return func > -- > Steve Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4