1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-03-01 15:47:42 +00:00

Explicitly check if an object is a class is pydispatch.

* This is to fix a disagreement in between CPython and PyPy.
* https://gist.github.com/4220533
This commit is contained in:
joehillen 2012-12-12 08:42:18 -08:00
parent 0bc5e4f9ec
commit 8778af5c5b

View File

@ -6,6 +6,8 @@ and subset the given arguments to match only
those which are acceptable. those which are acceptable.
""" """
import inspect
def function( receiver ): def function( receiver ):
"""Get function-like callable object for given receiver """Get function-like callable object for given receiver
@ -14,7 +16,7 @@ def function( receiver ):
If fromMethod is true, then the callable already If fromMethod is true, then the callable already
has its first argument bound has its first argument bound
""" """
if hasattr(receiver, '__call__'): if inspect.isclass(receiver) and hasattr(receiver, '__call__'):
# receiver is a class instance; assume it is callable. # receiver is a class instance; assume it is callable.
# Reassign receiver to the actual method that will be called. # Reassign receiver to the actual method that will be called.
if hasattr( receiver.__call__, 'im_func') or hasattr( receiver.__call__, 'im_code'): if hasattr( receiver.__call__, 'im_func') or hasattr( receiver.__call__, 'im_code'):