Use func.__qualname__ instead of func.__name__
See original GitHub issueBy using func.__qualname__
instead of func.__name__
we can apply the decorator to methods and get unique keys including the class’ name.
For example if we have two classes with a method with the same name, and we apply @cache_memoize
to both of them the same cache key will be used, unless we explicitly use prefix
. But IMHO doing as suggested is a safe default.
Just noticed that for Python 2 this would require adding some dependency like https://pypi.org/project/qualname/
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
What is __qualname__ in python? - Stack Overflow
I am asking what __qualname__ is and how it is used, not How do I get the fully qualified name... – Lord Elrond....
Read more >Function name printing should use __qualname ... - GitHub
The function name formatting is using the __name__ attribute of the function instead of __qualname__ , which results in incorrectly showing ...
Read more >What Is __qualname__ in Python - codingem.com
The __qualname__ attribute means qualified name in Python. ... Using __qualname__ is useful if you have a function and a method with the...
Read more >PEP 3155 – Qualified name for classes and functions
The repr() and str() of functions and classes is modified to use __qualname__ rather than __name__ . Example with nested classes. >>> class...
Read more >How to Get a Function Name as a String in Python? - thisPointer
The func_name does not work in the python 3 versions. If you want to get the class name and methods names as strings,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Agreed. I think it would be nice to upgrade, as you said, regardless. Since
__qualname__
is a “breaking change” it could easily fit in this, and it’s a nice improvement as users will need have one less concern in their heads.I’ll open a separate issue for the upgrade, and we can come back to this as well.
Yeap, I think it should now be just a drop in replacement 😃