[New-bugs-announce] [issue18334] type(name, bases, dict) does not call metaclass' __prepare__ attribute
Nikolaus Rath
report at bugs.python.org
Mon Jul 1 03:12:18 CEST 2013
New submission from Nikolaus Rath:
When using the three parameter form of type to create a new class, and any of the base classes has a metaclass with a __prepare__ function, the __prepare__ function is not executed:
>>> class CustomMetaclass(type):
... @classmethod
... def __prepare__(cls, name, bases):
... return { 'prepared_for': name }
...
>>> class ParentClass(metaclass=CustomMetaclass):
... pass
...
>>> class ClassOne(ParentClass):
... pass
...
>>> ClassTwo = type('ClassTwo', (ParentClass,), {})
>>> ClassOne.prepared_for
'ClassOne'
>>> ClassTwo.prepared_for
'ParentClass'
>>> 'prepared_for' in ClassOne.__dict__
True
>>> 'prepared_for' in ClassTwo.__dict__
False
I am not sure if that is intended behavior or not. I am attaching a doc patch for the case that this is intended.
----------
components: Interpreter Core
files: type_doc_patch.diff
keywords: patch
messages: 192099
nosy: Nikratio
priority: normal
severity: normal
status: open
title: type(name, bases, dict) does not call metaclass' __prepare__ attribute
type: behavior
versions: Python 3.3
Added file: http://bugs.python.org/file30737/type_doc_patch.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18334>
_______________________________________
More information about the New-bugs-announce
mailing list