mirror of
https://github.com/scrapy/scrapy.git
synced 2025-03-01 12:05:22 +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:
parent
0bc5e4f9ec
commit
8778af5c5b
@ -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'):
|
||||||
@ -46,4 +48,4 @@ def robustApply(receiver, *arguments, **named):
|
|||||||
del named[arg]
|
del named[arg]
|
||||||
return receiver(*arguments, **named)
|
return receiver(*arguments, **named)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user