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} |
Fred Drake | 26921da | 1999-06-17 18:58:02 +0000 | [diff] [blame] | 18 | This function creates an instance of \var{class} with dictionary |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 19 | \var{dict} without calling the \method{__init__()} constructor. Note that |
Fred Drake | 26921da | 1999-06-17 18:58:02 +0000 | [diff] [blame] | 20 | there are no guarantees that the object will be in a consistent state. |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 21 | \end{funcdesc} |
| 22 | |
| 23 | \begin{funcdesc}{instancemethod}{function, instance, class} |
| 24 | This function will return a method object, bound to \var{instance}, or |
Fred Drake | e019789 | 1999-06-17 18:15:07 +0000 | [diff] [blame] | 25 | unbound if \var{instance} is \code{None}. \var{function} must be |
| 26 | callable, and \var{instance} must be an instance object or |
| 27 | \code{None}. |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 28 | \end{funcdesc} |
| 29 | |
| 30 | \begin{funcdesc}{function}{code, globals\optional{, name\optional{argdefs}}} |
| 31 | Returns a (Python) function with the given code and globals. If |
Fred Drake | e019789 | 1999-06-17 18:15:07 +0000 | [diff] [blame] | 32 | \var{name} is given, it must be a string or \code{None}. If it is a |
| 33 | string, the function will have the given name, otherwise the function |
| 34 | name will be taken from \code{\var{code}.co_name}. If |
| 35 | \var{argdefs} is given, it must be a tuple and will be used to the |
| 36 | determine the default values of parameters. |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 37 | \end{funcdesc} |
| 38 | |
| 39 | \begin{funcdesc}{code}{argcount, nlocals, stacksize, flags, codestring, |
| 40 | constants, names, varnames, filename, name, firstlineno, |
| 41 | lnotab} |
Fred Drake | e019789 | 1999-06-17 18:15:07 +0000 | [diff] [blame] | 42 | This function is an interface to the \cfunction{PyCode_New()} C |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 43 | function. |
Fred Drake | 9e0b622 | 1999-06-29 15:45:09 +0000 | [diff] [blame] | 44 | %XXX This is still undocumented!!!!!!!!!!! |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 45 | \end{funcdesc} |
| 46 | |
| 47 | \begin{funcdesc}{module}{name} |
| 48 | This function returns a new module object with name \var{name}. |
Fred Drake | e019789 | 1999-06-17 18:15:07 +0000 | [diff] [blame] | 49 | \var{name} must be a string. |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 50 | \end{funcdesc} |
| 51 | |
| 52 | \begin{funcdesc}{classobj}{name, baseclasses, dict} |
| 53 | This function returns a new class object, with name \var{name}, derived |
| 54 | from \var{baseclasses} (which should be a tuple of classes) and with |
Fred Drake | e019789 | 1999-06-17 18:15:07 +0000 | [diff] [blame] | 55 | namespace \var{dict}. |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 56 | \end{funcdesc} |