[New-bugs-announce] [issue29114] __class__ not exists in the method which bounded by types.MethodType.

lanf0n report at bugs.python.org
Fri Dec 30 00:53:38 EST 2016


New submission from lanf0n:

test code below:

```python

>>> from types import MethodType
>>> class A:
...   def f(self):
...     print(__class__)
...
>>> a = A()
>>> a.fn = MethodType(lambda s: print(__class__), a)
>>>
>>> a.f()
<class '__main__.A'>
>>> a.fn()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <lambda>
NameError: name '__class__' is not defined
```

this behavior affect `super()` not work in patched function scope, 
of course we can use old super as super(self.__class__, self) to make it work as expected, but I think it should work as original method if we already bounded the function to instance(class).

----------
components: Library (Lib)
messages: 284313
nosy: lanfon72
priority: normal
severity: normal
status: open
title: __class__ not exists in the method which bounded by types.MethodType.
type: behavior
versions: Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29114>
_______________________________________


More information about the New-bugs-announce mailing list