From 8778af5c5be50a5d746751352f8d710d1f24681c Mon Sep 17 00:00:00 2001 From: joehillen Date: Wed, 12 Dec 2012 08:42:18 -0800 Subject: [PATCH] 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 --- scrapy/xlib/pydispatch/robustapply.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scrapy/xlib/pydispatch/robustapply.py b/scrapy/xlib/pydispatch/robustapply.py index 0350e60cf..f7a83da09 100644 --- a/scrapy/xlib/pydispatch/robustapply.py +++ b/scrapy/xlib/pydispatch/robustapply.py @@ -6,6 +6,8 @@ and subset the given arguments to match only those which are acceptable. """ +import inspect + def function( receiver ): """Get function-like callable object for given receiver @@ -14,7 +16,7 @@ def function( receiver ): If fromMethod is true, then the callable already 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. # Reassign receiver to the actual method that will be called. if hasattr( receiver.__call__, 'im_func') or hasattr( receiver.__call__, 'im_code'): @@ -46,4 +48,4 @@ def robustApply(receiver, *arguments, **named): del named[arg] return receiver(*arguments, **named) - \ No newline at end of file +