+0

Questions:

1. What's the use case for partial having __name__?
2. Does this imply it should have __qualname__ as well?
3. What name would be given to (an inherently anonymous) lambda?

Notes:

1. I would prefer __name__ to be more qualifying like its repr (e.g.
partial(foo, "x") → "<partial foo>")


On Mon, 2022-08-29 at 21:31 -0700, Charles Machalow wrote:
> 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 -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/WK3FO357ORPVAD3XRUBRH6IHIYSPS3G2/
> Code of Conduct: http://python.org/psf/codeofconduct/

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/6VD7SCZFP5KXGPRIFRTVYUUN7RANKZFR/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to