Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pydispatch/robustapply.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
and subset the given arguments to match only
those which are acceptable.
"""
import functools
import sys
if sys.hexversion >= 0x3000000:
im_func = '__func__'
Expand All @@ -25,6 +26,10 @@ def function( receiver ):
If fromMethod is true, then the callable already
has its first argument bound
"""
if isinstance(receiver, functools.partial):
# Get the code object and start index from bound function.
_, code_obj, start_idx = function(receiver.func)
return receiver, code_obj, start_idx
if hasattr(receiver, '__call__'):
# Reassign receiver to the actual method that will be called.
if hasattr( receiver.__call__, im_func) or hasattr( receiver.__call__, im_code):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_robustapply.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ def test03( self ):
def test04( self ):
"""Raise error on duplication of a particular argument"""
self.assertRaises( TypeError, robustApply, oneArgument, "this", blah = "that" )
def testPartials( self ):
func0 = functools.partial(noArgument)
robustApply(func0)

func1 = functools.partial(oneArgument, blah = 10)
robustApply(func1)

func2 = functools.partial(twoArgument, other = 10)
robustApply(func2, "first")

def getSuite():
return unittest.makeSuite(TestCases,'test')
Expand Down