| zhuyifei1999 added a comment. |
This error is from attempting to assign __full_name__ attribute to a built-in object of type instancemethod.
I guess cls.__init__ is a method bound to the class:
>>> (lambda: None).__get__(object()).__class__ <type 'instancemethod'>
so we could use __func__ to obtain the original function and deprecate it:
>>> (lambda: None).__get__(object()).__func__ <function <lambda> at 0x7f98ba39f668>But this breaks in python 3 when trying to access as a class attribute:
# python2 >>> meth = (lambda: None).__get__(object(), object); meth; meth.__class__; meth.__func__ <bound method object.<lambda> of <object object at 0x7f6e9f33e080>> <type 'instancemethod'> <function <lambda> at 0x7f6e9f31a5f0> >>> meth = (lambda: None).__get__(None, object); meth; meth.__class__; meth.__func__ <unbound method object.<lambda>> <type 'instancemethod'> <function <lambda> at 0x7f6e9f31a668> >>> # python3 >>> meth = (lambda: None).__get__(object(), object); meth; meth.__class__; meth.__func__ <bound method <lambda> of <object object at 0x7f5d5f5a5080>> <class 'method'> <function <lambda> at 0x7f5d5f4829d8> >>> meth = (lambda: None).__get__(None, object); meth; meth.__class__; meth.__func__ <function <lambda> at 0x7f5d5f482a60> <class 'function'> Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'function' object has no attribute '__func__' >>>Python 3 returns the function directly as a class attribute, whereas Python 2 returns a wrapper. The function does not have the __func__ attribute to get itself.
We could either use a try-except-AttributeError, or fetch the function from the __dict__, since we verified its existence anyways.
TASK DETAIL
EMAIL PREFERENCES
To: zhuyifei1999
Cc: zhuyifei1999, Aklapper, Wesalius, pywikibot-bugs-list, Magul, Tbscho, MayS, Mdupont, JJMC89, Avicennasis, mys_721tx, jayvdb, Dalba, Masti, Alchimista, Rxy
Cc: zhuyifei1999, Aklapper, Wesalius, pywikibot-bugs-list, Magul, Tbscho, MayS, Mdupont, JJMC89, Avicennasis, mys_721tx, jayvdb, Dalba, Masti, Alchimista, Rxy
_______________________________________________ pywikibot-bugs mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs
