Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Code simplification.

Iván de Prado0524df866936
diff --git a/scrapy/utils/reqser.py b/scrapy/utils/reqser.py
index 35a4fc72c..503d7b133 100644
--- a/scrapy/utils/reqser.py
+++ b/scrapy/utils/reqser.py
@@ -71,23 +71,19 @@ def request_from_dict(d, spider=None):
def _find_method(obj, func):
- if obj:
- try:
- func.__func__
- except AttributeError: # func is not a instance method. Not supported.
- pass
- else:
- 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
+ # Only instance methods contain ``__func__``
+ if obj and hasattr(func, '__func__'):
+ 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 an instance method in: %s" % (func, obj))