Open justdoit0823 opened 7 years ago
Just for some references, here's the line in the 3.0 changelog (second bullet):
https://docs.python.org/3.0/whatsnew/3.0.html#operators-and-special-methods
And the last bullet here (author is GvR)
http://www.artima.com/weblogs/viewpost.jsp?thread=86641#loose-ends
Edit: and here's the dev list discussion prior to the change https://mail.python.org/pipermail/python-dev/2005-January/050625.html
@jasonmyers Thanks, the above links are helpful.
Recently, I found a new interesting problem. When I import an another function within class body, the function is interpreted as an
instancemethod
in Python2 but not as the original. But when I test in Python 3, things seem to work in the intuitive way, and the name refers to the original function. We can easily test this case with IPython.In Python 2.
In Python 3.
We can also test with
type
. But why the behaviors are different in the two Python versions?Internally, the
function
type supports descriptor protocol and can be customized when accessed as a object's attribute. So the magic is hid in thefunc_descr_get
function.function
type's tp_descr_get implementation in Python 2function
type's tp_descr_get implementation in Python 3So it's obvious that a general function will not be interpreted as an instance method in Python 3. Does the Python 3 work in the right way?