Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 1 | \section{\module{new} --- |
| 2 | Runtime implementation object creation} |
| 3 | |
| 4 | \declaremodule{builtin}{new} |
| 5 | \sectionauthor{Moshe Zadka}{mzadka@geocities.com} |
| 6 | \modulesynopsis{Interface to the creation of runtime implementation objects.} |
| 7 | |
| 8 | |
| 9 | The \module{new} module allows an interface to the interpreter object |
| 10 | creation functions. This is for use primarily in marshal-type functions, |
| 11 | when a new object needs to be created ``magically'' and not by using the |
| 12 | regular creation functions. This module provides a low-level interface |
| 13 | to the interpreter, so care must be exercised when using this module. |
| 14 | |
| 15 | The \module{new} module defines the following functions: |
| 16 | |
| 17 | \begin{funcdesc}{instance}{class, dict} |
| 18 | This function creates an instance of \class{class} with dictionary |
| 19 | \var{dict} without calling the \method{__init__()} constructor. Note that |
| 20 | this means that there are no guarantees that the object will be in a |
| 21 | consistent state. |
| 22 | |
| 23 | Arguments are \emph{not} type-checked, and an incorrectly typed argument |
| 24 | will result in undefined behaviour. |
| 25 | \end{funcdesc} |
| 26 | |
| 27 | \begin{funcdesc}{instancemethod}{function, instance, class} |
| 28 | This function will return a method object, bound to \var{instance}, or |
| 29 | unbound if \var{instance} is \code{None}. It is checked that |
| 30 | \var{function} is callable, and that \var{instance} is an instance |
| 31 | object or \code{None}. |
| 32 | \end{funcdesc} |
| 33 | |
| 34 | \begin{funcdesc}{function}{code, globals\optional{, name\optional{argdefs}}} |
| 35 | Returns a (Python) function with the given code and globals. If |
| 36 | \var{name} is given, the function will have the given name. If |
| 37 | \var{argdefs} is given, they will be the function defaults. |
| 38 | \end{funcdesc} |
| 39 | |
| 40 | \begin{funcdesc}{code}{argcount, nlocals, stacksize, flags, codestring, |
| 41 | constants, names, varnames, filename, name, firstlineno, |
| 42 | lnotab} |
| 43 | This function is an interface to the \cfunction{PyCode_New()} internal |
| 44 | function. |
| 45 | XXX This is still undocumented!!!!!!!!!!! |
| 46 | \end{funcdesc} |
| 47 | |
| 48 | \begin{funcdesc}{module}{name} |
| 49 | This function returns a new module object with name \var{name}. |
| 50 | \var{name} should be a string. |
| 51 | \end{funcdesc} |
| 52 | |
| 53 | \begin{funcdesc}{classobj}{name, baseclasses, dict} |
| 54 | This function returns a new class object, with name \var{name}, derived |
| 55 | from \var{baseclasses} (which should be a tuple of classes) and with |
| 56 | namespace \var{dict}. All parameters are type checked. |
| 57 | \end{funcdesc} |