[issue29114] __class__ not exists in the method which bounded by types.MethodType.

2016-12-30 Thread lanf0n

lanf0n added the comment:

thanks xiang, Nick,

I might misunderstood MethodType to bound method will work as class definition.

It might not good to enhance MethodType to work as class definition, same 
problem on patching method to a class as Nick explained.

--

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



[issue29114] __class__ not exists in the method which bounded by types.MethodType.

2016-12-29 Thread lanf0n

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()

>>> a.fn()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1, in 
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 <rep...@bugs.python.org>
<http://bugs.python.org/issue29114>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com