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
Add the default attributes to functools.partial
#102323
Comments
Why do you need this? There are other callable objects that can miss >>> class MyCallable:
... def __call__(self, *args, **kwargs):
... print('whatever')
...
>>> MyCallable()()
whatever
>>> MyCallable().__qualname__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'MyCallable' object has no attribute '__qualname__' What is so special about Isn't |
That's a valid workaround for the usecase that prompted this ticket, but I still feel it wouldn't hurt to just use |
Was suggested in python/cpython#102323 by @sobolevn. Fixes pydantic#5101 Superceedes pydantic#5102
@JensHeinrich the problem with adding I prefer the status quo :) I hope my explanation helped! Thanks for the report. |
I do get the reasoning, but I will mention the discussion in #91002 as I see those points are related. This hopefully helps future me or other people researching it. |
* Use getattr and default for qualname Was suggested in python/cpython#102323 by @sobolevn. Fixes #5101 Superceedes #5102 * Import tests from #5102 * Fix signature generation for functools * Use getattr and default for name * Remove expectation of error from tests * Reset tracked validators * Describe changes * Use getattr and default for module * Use id as fallback * Tweak name formatting --------- Co-authored-by: JensHeinrich <github.com/JensHeinrich> Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
Feature or enhancement
Add
__qualname__
and__name__
tofunctools.partial
Pitch
Even an anonymous
lambda
function gets a__qualname__
or rather__name__
of<lambda>
andpartial
should behave in the same way.Previous discussion
This has been previously discussed in #78656, but as
lambda
-functions are named sincebefore ccd1921363ac7d a similiar behavior of using<partial>
as the name should have been suggested in the last discussion already.The text was updated successfully, but these errors were encountered: