Don't copy attributes that don't exist to partial instances

Classes don't have an `__name__` attribute, so when wrapping them in a `functools.partial` instance, don't try to copy it. Same goes for `__doc__`, but most objects should have that.
master
Dustin C. Hatch 2011-03-27 14:52:17 -05:00
parent 6cf47a0339
commit ab4ca55620
1 changed files with 4 additions and 2 deletions

View File

@ -50,8 +50,10 @@ class Router(object):
urlvars = match.groupdict()
urlvars.update(vars)
func = functools.partial(controller, **urlvars)
func.__name__ = controller.__name__
func.__doc__ = controller.__doc__
if hasattr(func, '__name__'):
func.__name__ = controller.__name__
if hasattr(func, '__doc__'):
func.__doc__ = controller.__doc__
self._cache[path_info] = func
return func
raise UnresolvedPath