question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use func.__qualname__ instead of func.__name__

See original GitHub issue

By 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:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Geekfishcommented, Jan 24, 2019

Right now we’re not suffering.

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.

0reactions
Geekfishcommented, Jun 11, 2019

Yeap, I think it should now be just a drop in replacement 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found