On Tue, Aug 30, 2022 at 03:28:06PM -0400, Wes Turner wrote:
> - Copying __qual/name__ would definitely be a performance regression
Doubtful that it would be meaningful. It's just a lookup and assignment.
>From the perspective of the partial object, it's just
self.__name__ = func.__name__
On Mon, Aug 29, 2022 at 09:31:25PM -0700, Charles Machalow wrote:
> Hey folks,
>
> I propose adding __name__ to functools.partial.
https://github.com/python/cpython/issues/91002
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe
On Wed, Aug 31, 2022, 12:24 AM Wes Turner wrote:
> +0.1
>
>
>
>
> On Tue, Aug 30, 2022, 11:15 PM Charles Machalow
> wrote:
>
>
>
>> ```
>> and for the simple test, added this to the partial definition:
>>
>> ```
>> @property
>> def __name__(self):
>> return
+0.1
On Tue, Aug 30, 2022, 11:15 PM Charles Machalow wrote:
> ```
> and for the simple test, added this to the partial definition:
>
> ```
> @property
> def __name__(self):
> return f"partial({self.func.__name__})"
> ```
> Of course it probably wouldn't be too bad to add in
I'd likely propose doing both as properties so that we don't need to hold
onto either of them... I was trying this out when I hit:
```
C:\Users\csm10495\Desktop\cpython\Scripts>ipython
Could not import runpy module
Traceback (most recent call last):
File "", line 1172, in _find_and_load
File
Actually, there is a good motive IMO for a partial function to have
__name__ and __qualname__: the code one is passing a partial function
might expect these attributes to be presented in the callable it get.
It is just a matter of unifying the interface for callables that are often
used as
Would a property or a copy be faster for existing and possible use cases?
In practice, how frequently will __qual/name__ be called on partials?
- Copying __qual/name__ would definitely be a performance regression
- There are probably as many use cases for partials as other methods of
functional
We may be able to do __name__/__qualname__ as a property to make it
evaluate when called as opposed to computed once on creation. That way we
just work with .func upon call so no need for extra references, etc.
As for documentation generation tools, it may be different at first, though
I believe
Is there a non-performance regressive way to proxy attr access to
func.__name__ of the partial function (or method; Callable)?
Would this affect documentation generation tools like e.g. sphinx-spidoc,
which IIRC use __name__ and probably now __qualname__ for generating
argspecs in RST for HTML
1: There are cases where one may need the __name__/__qualname__ of a given
callable. If someone uses partial to create a new callable, there is no
__name__/__qualname__ given. In my particular case, I'm logging what
callback function is passed to a different function... if someone uses
partial,
+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") → "")
On
11 matches
Mail list logo