[Python-Dev] Submitting PEP 422 (Simple class initialization hook) for pronouncement (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Mon Feb 11 09:02:43 CET 2013


On Sun, 10 Feb 2013 16:27:49 -0500 PJ Eby <pje at telecommunity.com> wrote:

On Sun, Feb 10, 2013 at 7:32 AM, Nick Coghlan <ncoghlan at gmail.com> wrote: > class Example: > @classmethod > def initclass(cls):

Is the @classmethod required? What happens if it's not present? Second, will type have a default initclass? (IMO, it should, otherwise it will be impossible to write co-operative initclass functions.) Only other comment is that the PEP could use a more concrete use case, e.g.: class Record: _fields = {} @classmethod def initclass(cls): _cls._fields = dict(cls.fields) # inherited fields _cls.fields.update({attr:val for attr, val in cls.dict.iteritems() if isinstance(val, Field)}) super().initclass() # be co-operative _# ...other methods that use the fields attribute class SomeRecord(Record): foo = Field(int) bar = Field(str) Putting something like this early on might help to demonstrate the usefulness of the feature on its own merits, independent of the porting issue, etc. ;-)

Can you explain what the example does / is supposed to do?



More information about the Python-Dev mailing list