Skip to content
Snippets Groups Projects
Commit e9d71e92 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Small refactor to _FileOrThing to iron out some bugs

parent d082cef9
No related branches found
No related tags found
No related merge requests found
......@@ -456,26 +456,21 @@ class _FileOrThing(object):
self.__func = None
def __call__(self, func):
def __call__(self, *args, **kwargs):
"""Creates and returns the decorated function. """
self.__func = func
# the first call will be our decorated
# function getting passed in.
if self.__func is None:
func = args[0]
self.__func = func
return self
# Wrap the wrapper because update_wrapper
# will raise an error if we pass it
# self.__wrapper. This is because it is
# not possible to set attributes on bound
# methods.
def wrapper(*args, **kwargs):
# Subsequent calls will be calls
# to the decorated function.
else:
return self.__wrapper(*args, **kwargs)
# We replace this __call__ method
# with the decorated function, so
# this instance is the decorator,
# and __get__ will work as intended.
self.__call__ = _update_wrapper(wrapper, func)
return self
def __get__(self, instance, owner):
"""Called when this ``_FileOrThing`` has been used to decorate a method
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment