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

FIX Avoid collisions when caching nested functions #1374

Merged
merged 10 commits into from
Feb 17, 2023

Conversation

cache-missing
Copy link
Contributor

the current implementation do not support nested function
if two nested function in different function have same name
such as this

def func1():
    def nested():
        ...
def func2():
    def nested():
        ...

then the get_func_name will return same module and name pair

@codecov
Copy link

codecov bot commented Dec 28, 2022

Codecov Report

Base: 93.94% // Head: 94.03% // Increases project coverage by +0.09% 🎉

Coverage data is based on head (4b87b71) compared to base (061d4ad).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1374      +/-   ##
==========================================
+ Coverage   93.94%   94.03%   +0.09%     
==========================================
  Files          52       52              
  Lines        7328     7341      +13     
==========================================
+ Hits         6884     6903      +19     
+ Misses        444      438       -6     
Impacted Files Coverage Δ
joblib/func_inspect.py 92.43% <100.00%> (+0.08%) ⬆️
joblib/test/test_func_inspect.py 91.36% <100.00%> (+0.74%) ⬆️
joblib/memory.py 95.52% <0.00%> (+0.26%) ⬆️
joblib/_parallel_backends.py 94.85% <0.00%> (+1.83%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

the current implementation do not support nested function
if two nested function in different function have same name
such as this
```python
def func1():
    def nested():
        ...
def func2():
    def nested():
        ...
```
then the get_func_name will return same module and name pair
Copy link
Contributor

@tomMoral tomMoral left a comment

Choose a reason for hiding this comment

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

This looks like a good change. Would you mind adding a test case for this?

Copy link
Contributor

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

LGTM.

@tomMoral, @ogrisel, I added a test and a change log entry. Note that it generates a backward incompatible change since all cached nested functions will now have a different module name, which will invalid all such caches. We discussed that irl with @tomMoral and decided that there is no guarantee that the cache can be preserved between versions.

Copy link
Contributor

@tomMoral tomMoral left a comment

Choose a reason for hiding this comment

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

just a small comment but otherwise, LGTM!

cachedir = tmpdir_factory.mktemp("joblib_test_func_inspect")
mem = Memory(cachedir.strpath)

@mem.cache
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need the memory here? If not, we can simplify

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed we don't need any cached function. I simplified the test.
This test fails on master because the module are the same.

joblib/test/test_func_inspect.py Outdated Show resolved Hide resolved
joblib/test/test_func_inspect.py Outdated Show resolved Hide resolved
joblib/test/test_func_inspect.py Outdated Show resolved Hide resolved
joblib/test/test_func_inspect.py Outdated Show resolved Hide resolved
@lesteve lesteve changed the title support nested function FIX Avoid collisions when caching nested functions Feb 17, 2023
@lesteve lesteve merged commit e4c00de into joblib:master Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants