blob: 25eb33e4429bc48f045c48d334ca9487d5bd02b2 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
2:mod:`new` --- Creation of runtime internal objects
3===================================================
4
5.. module:: new
6 :synopsis: Interface to the creation of runtime implementation objects.
Brett Cannond7265d62008-05-09 05:18:40 +00007 :deprecated:
8
9.. deprecated:: The new module has been removed in Python 3.0.
10
Georg Brandl8ec7f652007-08-15 14:28:01 +000011.. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
12
13
14The :mod:`new` module allows an interface to the interpreter object creation
15functions. This is for use primarily in marshal-type functions, when a new
16object needs to be created "magically" and not by using the regular creation
17functions. This module provides a low-level interface to the interpreter, so
18care must be exercised when using this module. It is possible to supply
19non-sensical arguments which crash the interpreter when the object is used.
20
21The :mod:`new` module defines the following functions:
22
23
24.. function:: instance(class[, dict])
25
26 This function creates an instance of *class* with dictionary *dict* without
27 calling the :meth:`__init__` constructor. If *dict* is omitted or ``None``, a
28 new, empty dictionary is created for the new instance. Note that there are no
29 guarantees that the object will be in a consistent state.
30
31
32.. function:: instancemethod(function, instance, class)
33
34 This function will return a method object, bound to *instance*, or unbound if
35 *instance* is ``None``. *function* must be callable.
36
37
38.. function:: function(code, globals[, name[, argdefs[, closure]]])
39
40 Returns a (Python) function with the given code and globals. If *name* is given,
41 it must be a string or ``None``. If it is a string, the function will have the
42 given name, otherwise the function name will be taken from ``code.co_name``. If
43 *argdefs* is given, it must be a tuple and will be used to determine the default
44 values of parameters. If *closure* is given, it must be ``None`` or a tuple of
45 cell objects containing objects to bind to the names in ``code.co_freevars``.
46
47
48.. function:: code(argcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab)
49
50 This function is an interface to the :cfunc:`PyCode_New` C function.
51
Georg Brandlb19be572007-12-29 10:57:00 +000052 .. XXX This is still undocumented!
Georg Brandl8ec7f652007-08-15 14:28:01 +000053
54
55.. function:: module(name[, doc])
56
57 This function returns a new module object with name *name*. *name* must be a
58 string. The optional *doc* argument can have any type.
59
60
61.. function:: classobj(name, baseclasses, dict)
62
63 This function returns a new class object, with name *name*, derived from
64 *baseclasses* (which should be a tuple of classes) and with namespace *dict*.
65