Skip to content

FIX Avoid collisions when caching nested functions#1374

Merged
lesteve merged 10 commits into
joblib:masterfrom
cache-missing:master
Feb 17, 2023
Merged

FIX Avoid collisions when caching nested functions#1374
lesteve merged 10 commits into
joblib:masterfrom
cache-missing:master

Conversation

@cache-missing

Copy link
Copy Markdown
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

@cache-missing
cache-missing force-pushed the master branch 2 times, most recently from 74cbb2d to 59cf40a Compare December 28, 2022 00:30
@codecov

codecov Bot commented Dec 28, 2022

Copy link
Copy Markdown

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

@tomMoral tomMoral left a comment

Copy link
Copy Markdown
Contributor

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?

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Contributor

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.

@tomMoral tomMoral left a comment

Copy link
Copy Markdown
Contributor

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!

Comment thread joblib/test/test_func_inspect.py Outdated
cachedir = tmpdir_factory.mktemp("joblib_test_func_inspect")
mem = Memory(cachedir.strpath)

@mem.cache

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread joblib/test/test_func_inspect.py Outdated
Comment thread joblib/test/test_func_inspect.py Outdated
Comment thread joblib/test/test_func_inspect.py Outdated
Comment thread joblib/test/test_func_inspect.py Outdated
@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.

4 participants