Hey folks,
I propose adding __name__ to functools.partial.
>>> get_name = functools.partial(input, "name: ")
>>> get_name()
name: hi
'hi'
>>> get_name.__name__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'functools.partial' object has no attribute '__name__'
>>> get_name.func
<built-in function input>
>>> get_name.func.__name__
'input'
We could set __name__ based off of partial.func.__name__ or we could try to
set it to something like 'partial calling func.__name__'
If the callable doesn't have a name, we could fall back to a None __name__
or set it to something generic.
Even lambdas have __name__ set:
>>> l = lambda: input('name: ')
>>> l.__name__
'<lambda>'
This proposal makes __name__ on partial objects more useful than the
current behavior of __name__ on lambda objects as well. We could port over
similar functionality to lambda if we'd like.
- Charlie Scott Machalow
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/WK3FO357ORPVAD3XRUBRH6IHIYSPS3G2/
Code of Conduct: http://python.org/psf/codeofconduct/