add comment to explain the use of __func__ instead of instance method objects

This commit is contained in:
Victor Torres 2020-04-16 11:37:03 -03:00
parent e0921cab66
commit 94c95020b3
No known key found for this signature in database
GPG Key ID: 5A646C47A34D7752
1 changed files with 7 additions and 0 deletions

View File

@ -80,6 +80,13 @@ def _find_method(obj, func):
if func_self is obj:
members = inspect.getmembers(obj, predicate=inspect.ismethod)
for name, obj_func in members:
# We need to use __func__ to access the original
# function object because instance method objects
# are generated each time attribute is retrieved from
# instance.
#
# Reference: The standard type hierarchy
# https://docs.python.org/3/reference/datamodel.html
if obj_func.__func__ is func.__func__:
return name
raise ValueError("Function %s is not a method of: %s" % (func, obj))