Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 1 | \section{\module{new} --- |
Fred Drake | f8ca7d8 | 2000-10-10 17:03:45 +0000 | [diff] [blame] | 2 | Creation of runtime internal objects} |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 3 | |
| 4 | \declaremodule{builtin}{new} |
Fred Drake | 57657bc | 2000-12-01 15:25:23 +0000 | [diff] [blame] | 5 | \sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il} |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 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. |
Raymond Hettinger | 8de636e | 2004-08-17 02:31:55 +0000 | [diff] [blame] | 14 | It is possible to supply non-sensical arguments which crash the |
| 15 | interpreter when the object is used. |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 16 | |
| 17 | The \module{new} module defines the following functions: |
| 18 | |
Fred Drake | c37f5b3 | 2001-01-28 17:23:05 +0000 | [diff] [blame] | 19 | \begin{funcdesc}{instance}{class\optional{, dict}} |
Fred Drake | 26921da | 1999-06-17 18:58:02 +0000 | [diff] [blame] | 20 | This function creates an instance of \var{class} with dictionary |
Fred Drake | c37f5b3 | 2001-01-28 17:23:05 +0000 | [diff] [blame] | 21 | \var{dict} without calling the \method{__init__()} constructor. If |
| 22 | \var{dict} is omitted or \code{None}, a new, empty dictionary is |
| 23 | created for the new instance. Note that there are no guarantees that |
| 24 | the object will be in a consistent state. |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 25 | \end{funcdesc} |
| 26 | |
| 27 | \begin{funcdesc}{instancemethod}{function, instance, class} |
| 28 | This function will return a method object, bound to \var{instance}, or |
Fred Drake | e019789 | 1999-06-17 18:15:07 +0000 | [diff] [blame] | 29 | unbound if \var{instance} is \code{None}. \var{function} must be |
Guido van Rossum | 4f3a62d | 2002-01-15 19:21:05 +0000 | [diff] [blame] | 30 | callable. |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 31 | \end{funcdesc} |
| 32 | |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 33 | \begin{funcdesc}{function}{code, globals\optional{, name\optional{, argdefs}}} |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 34 | Returns a (Python) function with the given code and globals. If |
Fred Drake | e019789 | 1999-06-17 18:15:07 +0000 | [diff] [blame] | 35 | \var{name} is given, it must be a string or \code{None}. If it is a |
| 36 | string, the function will have the given name, otherwise the function |
| 37 | name will be taken from \code{\var{code}.co_name}. If |
Fred Drake | 2c4f554 | 2000-10-10 22:00:03 +0000 | [diff] [blame] | 38 | \var{argdefs} is given, it must be a tuple and will be used to |
Fred Drake | e019789 | 1999-06-17 18:15:07 +0000 | [diff] [blame] | 39 | determine the default values of parameters. |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 40 | \end{funcdesc} |
| 41 | |
| 42 | \begin{funcdesc}{code}{argcount, nlocals, stacksize, flags, codestring, |
| 43 | constants, names, varnames, filename, name, firstlineno, |
| 44 | lnotab} |
Fred Drake | e019789 | 1999-06-17 18:15:07 +0000 | [diff] [blame] | 45 | This function is an interface to the \cfunction{PyCode_New()} C |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 46 | function. |
Fred Drake | 9e0b622 | 1999-06-29 15:45:09 +0000 | [diff] [blame] | 47 | %XXX This is still undocumented!!!!!!!!!!! |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 48 | \end{funcdesc} |
| 49 | |
Neal Norwitz | 116078f | 2005-10-11 03:23:45 +0000 | [diff] [blame] | 50 | \begin{funcdesc}{module}{name[, doc]} |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 51 | This function returns a new module object with name \var{name}. |
Fred Drake | e019789 | 1999-06-17 18:15:07 +0000 | [diff] [blame] | 52 | \var{name} must be a string. |
Neal Norwitz | 116078f | 2005-10-11 03:23:45 +0000 | [diff] [blame] | 53 | The optional \var{doc} argument can have any type. |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 54 | \end{funcdesc} |
| 55 | |
| 56 | \begin{funcdesc}{classobj}{name, baseclasses, dict} |
| 57 | This function returns a new class object, with name \var{name}, derived |
| 58 | from \var{baseclasses} (which should be a tuple of classes) and with |
Fred Drake | e019789 | 1999-06-17 18:15:07 +0000 | [diff] [blame] | 59 | namespace \var{dict}. |
Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 60 | \end{funcdesc} |