Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added update_wrapper to NotMemorizedFunc.__init__ #1358

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions joblib/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ class NotMemorizedFunc(object):
# Should be a light as possible (for speed)
def __init__(self, func):
self.func = func
try:
functools.update_wrapper(self, func)
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the linting error, could you use except BaseException:

"Objects like ufunc don't like that"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put the wrapping code in an helper and use it for both NotMemorizedFunc and MemorizedFunc?

Also, could you also set the doc string of the function, as it is done for MemorizedFunc?


def __call__(self, *args, **kwargs):
return self.func(*args, **kwargs)
Expand Down
3 changes: 3 additions & 0 deletions joblib/test/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,9 @@ def test_memorized_pickling(tmpdir):
assert result2.get() == result.get()
os.remove(filename)

def test_func_attrs(tmpdir):
assert NotMemorizedFunc(f).__name__ == 'f'
assert MemorizedFunc(f, tmpdir.strpath).__name__ == 'f'

def test_memorized_repr(tmpdir):
func = MemorizedFunc(f, tmpdir.strpath)
Expand Down