On 29 April 2017 at 03:00, Mike Miller <python-id...@mgmiller.net> wrote:
> On 2017-04-28 06:07, Nick Coghlan wrote:
>> For a *lot* of classes, what we want to be able to define is:
>>
>> - a set of data fields
>> - a basic initialiser to set those fields by name
>> - a repr based on those fields (or a subset)
>> - equality comparisons based on those fields (or a subset)
>> - ordering comparisons based on those fields (or a subset)
>> - conversion to a JSON-friendly dict
>> - pickling support
>> - copying support
>
>
> Nice!  I've implemented a higher-level base class in a few projects that
> does just this.  Things like pickling and JSON I might want to put into
> "mixins", but yes the majority of these would be nice to have implemented by
> default "batteries included" style.  I prefer a base class to decorators
> since they seem to stay out of the way more:
>
>     class Vehicle(BaseObject, Picklable):
>         …

Putting any questions of aesthetics aside, the main argument in favour
of using a base class and __init_subclass__ for autoclass definitions
would be the fact that further subclasses would automatically get the
magic method construction executed, rather than requiring that the
class decorator be repeated on the subclass.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to