__prepare__ metaclass's method
ast
nomail at com.invalid
Fri Oct 28 09:24:51 EDT 2016
More information about the Python-list mailing list
Fri Oct 28 09:24:51 EDT 2016
- Previous message (by thread): Installing Python on Windows 7
- Next message (by thread): __prepare__ metaclass's method
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi On python doc here: https://docs.python.org/3.4/reference/datamodel.html it is said about __prepare__ metaclass's method: If the metaclass has a __prepare__ attribute, it is called as namespace = metaclass.__prepare__(name, bases, **kwds) where the additional keyword arguments, if any, come from the class definition. I don't understand what they call the "class definition". So I took their example and add a print(kwds) class OrderedClass(type): @classmethod def __prepare__(metacls, name, bases, **kwds): print(kwds) return collections.OrderedDict() def __new__(cls, name, bases, namespace, **kwds): result = type.__new__(cls, name, bases, dict(namespace)) result.members = tuple(namespace) return result class A(metaclass=OrderedClass): def one(self): pass def two(self): pass def three(self): pass def four(self): pass but print(kwds) outputs an empty dictionnary {} So what kwds is supposed to contains ? Thx
- Previous message (by thread): Installing Python on Windows 7
- Next message (by thread): __prepare__ metaclass's method
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list