Open
Conversation
zzzeek
requested changes
May 19, 2024
Member
zzzeek
left a comment
There was a problem hiding this comment.
this is nice, I wonder if we should just switch to using __qualname__ across the board by default. we'd want to do a bigger version bump for that. but let's start with this
|
|
||
|
|
||
| def function_key_generator(namespace, fn, to_str=str): | ||
| def function_key_generator(namespace, fn, to_str=str, use_qual_name=False): |
Member
There was a problem hiding this comment.
how about also in:
def function_multi_key_generatordef kwarg_function_key_generator
| return nested | ||
|
|
||
|
|
||
| def test_function_key_generator_qualname(): |
Member
There was a problem hiding this comment.
I would break up each test case here and have them come in using pytest.mark.parametrize as a decorator on def test_function_key_generator_qualname. so one function, but the cases come in parameters. each parameter results in one test.
| ) | ||
|
|
||
|
|
||
| def test_function_key_generator(): |
Member
There was a problem hiding this comment.
same here, then also for the multi key and kwarg versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi there! This PR adds the possibility to use a function's full qualified name while building the cache key, an attribute that has been available since python 3.3 so it is safe to be relied upon here.
This PR comes from a bug hunting I did today whose root cause was key collision. We had a structure that looked roughly like this:
When both
activemethods are cached, their keys end up colliding because:but:
In [5]: B.active.__qualname__ Out[5]: 'B.active'Hope this is useful 🙌