blob: 438329f44a9bcb9d48f824edc711a97160e1ec8a [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
2:mod:`new` --- Creation of runtime internal objects
3===================================================
4
5.. module:: new
6 :synopsis: Interface to the creation of runtime implementation objects.
7.. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
8
9
10The :mod:`new` module allows an interface to the interpreter object creation
11functions. This is for use primarily in marshal-type functions, when a new
12object needs to be created "magically" and not by using the regular creation
13functions. This module provides a low-level interface to the interpreter, so
14care must be exercised when using this module. It is possible to supply
15non-sensical arguments which crash the interpreter when the object is used.
16
17The :mod:`new` module defines the following functions:
18
19
20.. function:: instancemethod(function, instance, class)
21
22 This function will return a method object, bound to *instance*, or unbound if
23 *instance* is ``None``. *function* must be callable.
24
25
26.. function:: function(code, globals[, name[, argdefs[, closure]]])
27
28 Returns a (Python) function with the given code and globals. If *name* is given,
29 it must be a string or ``None``. If it is a string, the function will have the
30 given name, otherwise the function name will be taken from ``code.co_name``. If
31 *argdefs* is given, it must be a tuple and will be used to determine the default
32 values of parameters. If *closure* is given, it must be ``None`` or a tuple of
33 cell objects containing objects to bind to the names in ``code.co_freevars``.
34
35
36.. function:: code(argcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab)
37
38 This function is an interface to the :cfunc:`PyCode_New` C function.
39
Georg Brandl81ac1ce2007-08-31 17:17:17 +000040 .. XXX This is still undocumented!!!
Georg Brandl116aa622007-08-15 14:28:22 +000041
42
43.. function:: module(name[, doc])
44
45 This function returns a new module object with name *name*. *name* must be a
46 string. The optional *doc* argument can have any type.
47
48
49.. function:: classobj(name, baseclasses, dict)
50
51 This function returns a new class object, with name *name*, derived from
52 *baseclasses* (which should be a tuple of classes) and with namespace *dict*.
53