[Python-Dev] cpython: Close #14588: added a PEP 3115 compliant dynamic type creation mechanism (original) (raw)
Georg Brandl g.brandl at gmx.net
Mon May 21 20:14:36 CEST 2012
- Previous message: [Python-Dev] cpython (3.2): #14766: Add correct algorithm for when a 'time' object is naive.
- Next message: [Python-Dev] cpython (3.2): Issue12541 - Add UserWarning for unquoted realms
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Am 19.05.2012 18:34, schrieb nick.coghlan:
diff --git a/Doc/library/types.rst b/Doc/library/types.rst --- a/Doc/library/types.rst +++ b/Doc/library/types.rst @@ -1,5 +1,5 @@ -:mod:
types
--- Names for built-in types -========================================= +:mod:types
--- Dynamic type creation and names for built-in types +===================================================================.. module:: types :synopsis: Names for built-in types. @@ -8,20 +8,69 @@ -------------- -This module defines names for some object types that are used by the standard +This module defines utility function to assist in dynamic creation of +new types. + +It also defines names for some object types that are used by the standard Python interpreter, but not exposed as builtins like :class:
int
or -:class:str
are. Also, it does not include some of the types that arise -transparently during processing such as thelistiterator
type. +:class:str
are. -Typical use is for :func:isinstance
or :func:issubclass
checks. -The module defines the following names: +Dynamic Type Creation +--------------------- + +.. function:: newclass(name, bases=(), kwds=None, execbody=None) + + Creates a class object dynamically using the appropriate metaclass. + + The arguments are the components that make up a class definition: the + class name, the base classes (in order), the keyword arguments (such as +metaclass
) and the callback function to populate the class namespace. + + The execbody callback should accept the class namespace as its sole + argument and update the namespace directly with the class contents. + +.. function:: prepareclass(name, bases=(), kwds=None) + + Calculates the appropriate metaclass and creates the class namespace. + + The arguments are the components that make up a class definition: the + class name, the base classes (in order) and the keyword arguments (such as +metaclass
). + + The return value is a 3-tuple:metaclass, namespace, kwds
+ + metaclass is the appropriate metaclass + namespace is the prepared class namespace + kwds is an updated copy of the passed in kwds argument with any +'metaclass'
entry removed. If no kwds argument is passed in, this + will be an empty dict. + + +.. seealso:: + + :pep:3115
- Metaclasses in Python 3000 + Introduced the_prepare_
namespace hook + +
Should have versionadded.
Georg
- Previous message: [Python-Dev] cpython (3.2): #14766: Add correct algorithm for when a 'time' object is naive.
- Next message: [Python-Dev] cpython (3.2): Issue12541 - Add UserWarning for unquoted realms
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]