[Python-Dev] Providing a mechanism for PEP 3115 compliant dynamic class creation

Nick Coghlan ncoghlan at gmail.com
Mon Apr 16 04:17:41 CEST 2012

On Mon, Apr 16, 2012 at 5:34 AM, Daniel Urban <urban.dani+py at gmail.com> wrote:
> On Sun, Apr 15, 2012 at 13:48, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> /me pages thoughts from 12 months ago back into brain...
> Sorry about that, I planned to do this earlier...

No worries - good to have someone following up on it, since it had
completely dropped off my own radar :)

>> No, I think we would want to expose the created namespace directly -
>> that way people can use update(), direct assigment, exec(), eval(), or
>> whatever other mechanism they choose to handle the task of populating
>> the namespace. However, a potentially cleaner way to do that might be
>> offer use an optional callback API rather than exposing a separate
>> public prepare() function. Something like:
>>    def build_class(name, bases=(), kwds=None, eval_body=None):
>>        metaclass, ns = _prepare(name, bases, kwds)
>>        if eval_body is not None:
>>            eval_body(ns)
>>        return metaclass(name, bases, ns)
> That seems more flexible indeed. I will try to make a patch next week,
> if that's OK.

Sure, just create a new tracker issue and assign it to me. You already
know better than most what the _prepare() step needs to do :)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list