Neil Girdhar <mistersh...@gmail.com> added the comment: 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? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33419> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com