Metaclasses - magic functions

Ethan Furman ethan at stoneleaf.us
Tue Dec 20 18:56:10 EST 2016


On 12/20/2016 03:26 PM, Ian Kelly wrote:

> ... The latter is interesting mostly because it allows you to set the
> __slots__ or do something interesting with the __prepare__ hook
> (although the only interesting thing I've ever seen done with
> __prepare__ is to use an OrderedDict to preserve the the definition
> order of the class attributes; now that Python 3.6 does this by default
>  it's probably obsolete).

__prepare__ is not obsolete.  Enum uses it to set a custom dictionary which tracks the new members, etc.

--
~Ethan~


More information about the Python-list mailing list