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

PJ Eby pje at telecommunity.com
Sun Feb 10 22:27:49 CET 2013


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 init_class? (IMO, it should, otherwise it will be impossible to write co-operative init_class functions.)

Only other comment is that the PEP could use a more concrete use case, e.g.:

class Record:
    __fields = {}

    @classmethod
    def __init_class__(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().init_class() # 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. ;-)



More information about the Python-Dev mailing list