diff -r 4a37bed5b96f Doc/library/types.rst --- a/Doc/library/types.rst Wed Aug 29 17:52:06 2012 +0300 +++ b/Doc/library/types.rst Wed Aug 29 09:59:00 2012 -0700 @@ -72,36 +72,62 @@ Typical use of these names is for :func:`isinstance` or :func:`issubclass` checks. -Standard names are defined for the following types: -.. data:: FunctionType - LambdaType ++---------------------------+------------------------------------------+ +| Type Name | Type Description | ++===========================+==========================================+ +| :class:`CodeType` | The type for code objects such as | +| | returned by :func:`compile` | ++---------------------------+------------------------------------------+ +| :class:`FunctionType` | The type of user-defined functions and | +| | functions created by :keyword:`lambda` | +| :class:`LambdaType` | expressions. | ++---------------------------+------------------------------------------+ +| :class:`SimpleNamespace` | A simple attribute-based namespace. | ++---------------------------+------------------------------------------+ +| :class:`MethodType` | Create a bound instance method object. | +| | The type of methods of user-defined class| +| | instances. | ++---------------------------+------------------------------------------+ - The type of user-defined functions and functions created by - :keyword:`lambda` expressions. +Standard names are defined for the following types: + +.. class:: FunctionType(code, globals) +.. class:: LambdaType(code, globals) + + LambaType is a synonym for FunctionType() + + Create a function object from a code object and a dictionary. + The optional name string overrides the name from the code object. + The optional argdefs tuple specifiees the default argument values. + The optional closure tuple supplies the bindings for free variables. .. data:: GeneratorType + This does support direct creation. + Please see :class:`GeneratorType` (imp.new_module) The type of :term:`generator`-iterator objects, produced by calling a generator function. -.. data:: CodeType +.. class:: CodeType(argcount, kwonlyargcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab) + + Create a code object. Not for the faint of heart. .. index:: builtin: compile - The type for code objects such as returned by :func:`compile`. -.. data:: MethodType +.. class:: MethodType(function, instance) - The type of methods of user-defined class instances. .. data:: BuiltinFunctionType BuiltinMethodType + This does support direct creation. + Please see :class:`ModuleType` (imp.new_module). The type of built-in functions like :func:`len` or :func:`sys.exit`, and methods of built-in classes. (Here, the term "built-in" means "written in C".) @@ -114,17 +140,26 @@ .. data:: TracebackType + + This does support direct creation. + Please see :class:`ModuleType` (imp.new_module). The type of traceback objects such as found in ``sys.exc_info()[2]``. .. data:: FrameType + This does support direct creation. + Please see :class:`FrameType` (imp.new_module) + The type of frame objects such as found in ``tb.tb_frame`` if ``tb`` is a traceback object. .. data:: GetSetDescriptorType + + This does support direct creation. + Please see :class:`GetSetDescriptorType` (imp.new_module). The type of objects defined in extension modules with ``PyGetSetDef``, such as ``FrameType.f_locals`` or ``array.array.typecode``. This type is used as descriptor for object attributes; it has the same purpose as the @@ -133,6 +168,8 @@ .. data:: MemberDescriptorType + This does support direct creation. + Please see :class:`MemberDescriptorType` (imp.new_module). The type of objects defined in extension modules with ``PyMemberDef``, such as ``datetime.timedelta.days``. This type is used as descriptor for simple C data members which use standard conversion functions; it has the same purpose @@ -146,8 +183,8 @@ .. class:: MappingProxyType(mapping) Read-only proxy of a mapping. It provides a dynamic view on the mapping's - entries, which means that when the mapping changes, the view reflects these - changes. + entries, which means that when the mapping changes, the view reflects + these changes. .. versionadded:: 3.3 @@ -196,6 +233,8 @@ .. class:: SimpleNamespace + namespace(**kwargs) + A simple :class:`object` subclass that provides attribute access to its namespace, as well as a meaningful repr. diff -r 4a37bed5b96f Objects/descrobject.c --- a/Objects/descrobject.c Wed Aug 29 17:52:06 2012 +0300 +++ b/Objects/descrobject.c Wed Aug 29 09:59:00 2012 -0700 @@ -919,7 +919,9 @@ _PyObject_GC_TRACK(mappingproxy); return (PyObject *)mappingproxy; } - +PyDoc_STRVAR(mappingproxy_doc,"It's a simple API that accepts a single\n" + "parameter (which must be a mapping) and returns a read-only\n" + "view of the original mapping."); PyTypeObject PyDictProxy_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "mappingproxy", /* tp_name */ @@ -942,7 +944,7 @@ 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - 0, /* tp_doc */ + mappingproxy_doc, /* tp_doc */ mappingproxy_traverse, /* tp_traverse */ 0, /* tp_clear */ (richcmpfunc)mappingproxy_richcompare, /* tp_richcompare */ @@ -960,6 +962,7 @@ 0, /* tp_init */ 0, /* tp_alloc */ mappingproxy_new, /* tp_new */ + }; PyObject *