blob: d0394d1086d24a46de8bf7003216a4c7a1597e07 [file] [log] [blame]
Fred Drake64bc94e1999-06-17 15:11:35 +00001\section{\module{new} ---
Fred Drakef8ca7d82000-10-10 17:03:45 +00002 Creation of runtime internal objects}
Fred Drake64bc94e1999-06-17 15:11:35 +00003
4\declaremodule{builtin}{new}
Fred Drake57657bc2000-12-01 15:25:23 +00005\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
Fred Drake64bc94e1999-06-17 15:11:35 +00006\modulesynopsis{Interface to the creation of runtime implementation objects.}
7
8
9The \module{new} module allows an interface to the interpreter object
10creation functions. This is for use primarily in marshal-type functions,
11when a new object needs to be created ``magically'' and not by using the
12regular creation functions. This module provides a low-level interface
13to the interpreter, so care must be exercised when using this module.
Raymond Hettinger8de636e2004-08-17 02:31:55 +000014It is possible to supply non-sensical arguments which crash the
15interpreter when the object is used.
Fred Drake64bc94e1999-06-17 15:11:35 +000016
17The \module{new} module defines the following functions:
18
Fred Drakec37f5b32001-01-28 17:23:05 +000019\begin{funcdesc}{instance}{class\optional{, dict}}
Fred Drake26921da1999-06-17 18:58:02 +000020This function creates an instance of \var{class} with dictionary
Fred Drakec37f5b32001-01-28 17:23:05 +000021\var{dict} without calling the \method{__init__()} constructor. If
22\var{dict} is omitted or \code{None}, a new, empty dictionary is
23created for the new instance. Note that there are no guarantees that
24the object will be in a consistent state.
Fred Drake64bc94e1999-06-17 15:11:35 +000025\end{funcdesc}
26
27\begin{funcdesc}{instancemethod}{function, instance, class}
28This function will return a method object, bound to \var{instance}, or
Fred Drakee0197891999-06-17 18:15:07 +000029unbound if \var{instance} is \code{None}. \var{function} must be
Guido van Rossum4f3a62d2002-01-15 19:21:05 +000030callable.
Fred Drake64bc94e1999-06-17 15:11:35 +000031\end{funcdesc}
32
Georg Brandl9fd21e32006-07-29 08:51:21 +000033\begin{funcdesc}{function}{code, globals\optional{, name\optional{,
34 argdefs\optional{, closure}}}}
Fred Drake64bc94e1999-06-17 15:11:35 +000035Returns a (Python) function with the given code and globals. If
Fred Drakee0197891999-06-17 18:15:07 +000036\var{name} is given, it must be a string or \code{None}. If it is a
37string, the function will have the given name, otherwise the function
38name will be taken from \code{\var{code}.co_name}. If
Fred Drake2c4f5542000-10-10 22:00:03 +000039\var{argdefs} is given, it must be a tuple and will be used to
Georg Brandl9fd21e32006-07-29 08:51:21 +000040determine the default values of parameters. If \var{closure} is given,
41it must be \code{None} or a tuple of cell objects containing objects
42to bind to the names in \code{\var{code}.co_freevars}.
Fred Drake64bc94e1999-06-17 15:11:35 +000043\end{funcdesc}
44
45\begin{funcdesc}{code}{argcount, nlocals, stacksize, flags, codestring,
46 constants, names, varnames, filename, name, firstlineno,
47 lnotab}
Fred Drakee0197891999-06-17 18:15:07 +000048This function is an interface to the \cfunction{PyCode_New()} C
Fred Drake64bc94e1999-06-17 15:11:35 +000049function.
Fred Drake9e0b6221999-06-29 15:45:09 +000050%XXX This is still undocumented!!!!!!!!!!!
Fred Drake64bc94e1999-06-17 15:11:35 +000051\end{funcdesc}
52
Neal Norwitz116078f2005-10-11 03:23:45 +000053\begin{funcdesc}{module}{name[, doc]}
Fred Drake64bc94e1999-06-17 15:11:35 +000054This function returns a new module object with name \var{name}.
Fred Drakee0197891999-06-17 18:15:07 +000055\var{name} must be a string.
Neal Norwitz116078f2005-10-11 03:23:45 +000056The optional \var{doc} argument can have any type.
Fred Drake64bc94e1999-06-17 15:11:35 +000057\end{funcdesc}
58
59\begin{funcdesc}{classobj}{name, baseclasses, dict}
60This function returns a new class object, with name \var{name}, derived
61from \var{baseclasses} (which should be a tuple of classes) and with
Fred Drakee0197891999-06-17 18:15:07 +000062namespace \var{dict}.
Fred Drake64bc94e1999-06-17 15:11:35 +000063\end{funcdesc}