Skip to content

Commit

Permalink
Explicitly check if an object is a class is pydispatch.
Browse files Browse the repository at this point in the history
* This is to fix a disagreement in between CPython and PyPy.
* https://gist.github.com/4220533
  • Loading branch information
joehillen committed Dec 12, 2012
1 parent 0bc5e4f commit 8778af5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scrapy/xlib/pydispatch/robustapply.py
Expand Up @@ -6,6 +6,8 @@
those which are acceptable.
"""

import inspect

def function( receiver ):
"""Get function-like callable object for given receiver
Expand All @@ -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'):
Expand Down Expand Up @@ -46,4 +48,4 @@ def robustApply(receiver, *arguments, **named):
del named[arg]
return receiver(*arguments, **named)



0 comments on commit 8778af5

Please sign in to comment.