This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author NeilGirdhar
Recipients NeilGirdhar, eric.smith, ncoghlan, rhettinger, serhiy.storchaka
Date 2018-05-04.11:40:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1525434032.84.0.682650639539.issue33419@psf.upfronthosting.co.za>
In-reply-to
Content
I'm not sure that this should be in the stdlib. The three-line function can be enough for your simple case, and it is too simple for including it in the stdlib. But for general stdlib quality solution it lacks many details.

1. It doesn't work with classes that implement the constructor as __new__, but not __init__. It may need of using metaclasses with overridden __call__. But how then handle classes with custom metaclasses?

Can you illustrate how you would do it for these kinds of classes?

Anyway, I think using __new__ on user classes is extremely rare.

2. inspect.signature() doesn't give the correct signature as for partial(). This requires changing the inspect module.

Good point.  I can look into this.

3. pickling and copying of instances are broken in many cases. Pickling a class is always broken. I afraid that this can't be solved without significant reworking of the pickle and the copy modules.

Okay, interesting, but this doesn't seem relevant to partialclass.

4. It adds instance attributes __dict__ and __weakref__ even if they were disabled by using __slots__. This increases the size of instances and breaks some properties.

Can we just copy the parent class' __slots__ to the partialclass return value?

5. repr() of the class doesn't show that it is a partialclass (unlike to the result of partial()).

I will fix this.

6. Many alternate constructors and copying methods are broken. For example the copy() method of partialclass(defaultdict, list) in your example. There is no general solution of this, it should be solved individually for every class.

Ultimately, if pickling works, then copying should work too.  The usual way I do it is implementing __getnewargs__, etc.   This should work fine?

> If there is a need of this feature in the stdlib, it needs changing many parts of the stdlib. And the result will still need an additional work for every concrete class.

Fair enough.

> Also note that the term "partial class" has different well known meaning in some other programming languages: https://en.wikipedia.org/wiki/Class_(computer_programming)#Partial .

Interesting.  Similarly "partial function" means something else.  That's why I changed the documentation to use the terms: "partial class application", "partial function application", and "partial method application".  All of these are "partial applications": https://en.wikipedia.org/wiki/Partial_application .

Should we discuss this on github?
History
Date User Action Args
2018-05-04 11:40:32NeilGirdharsetrecipients: + NeilGirdhar, rhettinger, ncoghlan, eric.smith, serhiy.storchaka
2018-05-04 11:40:32NeilGirdharsetmessageid: <1525434032.84.0.682650639539.issue33419@psf.upfronthosting.co.za>
2018-05-04 11:40:32NeilGirdharlinkissue33419 messages
2018-05-04 11:40:32NeilGirdharcreate