Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
35da5905
Commit
35da5905
authored
Nov 25, 1998
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Massive change to just about every construct that impacts the index.
Blame it on Just. ;-)
parent
83d66b28
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
210 additions
and
225 deletions
+210
-225
Doc/ref/ref3.tex
Doc/ref/ref3.tex
+210
-225
No files found.
Doc/ref/ref3.tex
View file @
35da5905
...
@@ -110,8 +110,9 @@ object, if it has any.
...
@@ -110,8 +110,9 @@ object, if it has any.
\index
{
attribute
}
\index
{
attribute
}
\indexii
{
special
}{
attribute
}
\indexii
{
special
}{
attribute
}
\indexiii
{
generic
}{
special
}{
attribute
}
\indexiii
{
generic
}{
special
}{
attribute
}
\ttindex
{__
methods
__}
\withsubitem
{
(built-in object attribute)
}{
%
\ttindex
{__
members
__}
\ttindex
{__
methods
__}
\ttindex
{__
members
__}}
\begin{description}
\begin{description}
...
@@ -387,12 +388,13 @@ defines the global namespace of the module in which the function was
...
@@ -387,12 +388,13 @@ defines the global namespace of the module in which the function was
defined. Additional information about a function's definition can be
defined. Additional information about a function's definition can be
retrieved from its code object; see the description of internal types
retrieved from its code object; see the description of internal types
below.
below.
\ttindex
{
func
_
doc
}
\withsubitem
{
(function attribute)
}{
%
\ttindex
{__
doc
__}
\ttindex
{
func
_
doc
}
%
\ttindex
{__
name
__}
\ttindex
{__
doc
__}
%
\ttindex
{
func
_
defaults
}
\ttindex
{__
name
__}
%
\ttindex
{
func
_
code
}
\ttindex
{
func
_
defaults
}
%
\ttindex
{
func
_
globals
}
\ttindex
{
func
_
code
}
%
\ttindex
{
func
_
globals
}}
\indexii
{
global
}{
namespace
}
\indexii
{
global
}{
namespace
}
\item
[User-defined methods]
\item
[User-defined methods]
...
@@ -409,6 +411,9 @@ base class of the class of which \member{im_self} is an instance);
...
@@ -409,6 +411,9 @@ base class of the class of which \member{im_self} is an instance);
\member
{__
doc
__}
is the method's documentation (same as
\member
{__
doc
__}
is the method's documentation (same as
\code
{
im
_
func.
__
doc
__}
);
\member
{__
name
__}
is the method name (same as
\code
{
im
_
func.
__
doc
__}
);
\member
{__
name
__}
is the method name (same as
\code
{
im
_
func.
__
name
__}
).
\code
{
im
_
func.
__
name
__}
).
\withsubitem
{
(method attribute)
}{
%
\ttindex
{
im
_
func
}
%
\ttindex
{
im
_
self
}}
User-defined method objects are created in two ways: when getting an
User-defined method objects are created in two ways: when getting an
attribute of a class that is a user-defined function object, or when
attribute of a class that is a user-defined function object, or when
...
@@ -425,6 +430,10 @@ function \method{f()}, \code{C.f} does not yield the function object
...
@@ -425,6 +430,10 @@ function \method{f()}, \code{C.f} does not yield the function object
instance,
\code
{
x.f
}
yields a bound method object
\code
{
m
}
where
instance,
\code
{
x.f
}
yields a bound method object
\code
{
m
}
where
\code
{
m.im
_
class
}
is
\code
{
C
}
,
\code
{
m.im
_
func
}
is
\method
{
f()
}
, and
\code
{
m.im
_
class
}
is
\code
{
C
}
,
\code
{
m.im
_
func
}
is
\method
{
f()
}
, and
\code
{
m.im
_
self
}
is
\code
{
x
}
.
\code
{
m.im
_
self
}
is
\code
{
x
}
.
\withsubitem
{
(method attribute)
}{
%
\ttindex
{
im
_
class
}
%
\ttindex
{
im
_
func
}
%
\ttindex
{
im
_
self
}}
When an unbound user-defined method object is called, the underlying
When an unbound user-defined method object is called, the underlying
function (
\member
{
im
_
func
}
) is called, with the restriction that the
function (
\member
{
im
_
func
}
) is called, with the restriction that the
...
@@ -446,9 +455,6 @@ Also notice that this transformation only happens for user-defined
...
@@ -446,9 +455,6 @@ Also notice that this transformation only happens for user-defined
functions; other callable objects (and all non-callable objects) are
functions; other callable objects (and all non-callable objects) are
retrieved without transformation.
retrieved without transformation.
\ttindex
{
im
_
func
}
\ttindex
{
im
_
self
}
\item
[Built-in functions]
\item
[Built-in functions]
A built-in function object is a wrapper around a
\C
{}
function. Examples
A built-in function object is a wrapper around a
\C
{}
function. Examples
of built-in functions are
\function
{
len()
}
and
\function
{
math.sin()
}
of built-in functions are
\function
{
len()
}
and
\function
{
math.sin()
}
...
@@ -482,7 +488,7 @@ returned. This implies a call to the class's \method{__init__()} method
...
@@ -482,7 +488,7 @@ returned. This implies a call to the class's \method{__init__()} method
if it has one. Any arguments are passed on to the
\method
{__
init
__
()
}
if it has one. Any arguments are passed on to the
\method
{__
init
__
()
}
method. If there is no
\method
{__
init
__
()
}
method, the class must be called
method. If there is no
\method
{__
init
__
()
}
method, the class must be called
without arguments.
without arguments.
\
ttindex
{__
init
__
}
\
withsubitem
{
(object method)
}{
\ttindex
{__
init
__
()
}
}
\obindex
{
class
}
\obindex
{
class
}
\obindex
{
class instance
}
\obindex
{
class instance
}
\obindex
{
instance
}
\obindex
{
instance
}
...
@@ -514,7 +520,7 @@ e.g., \samp{m.x = 1} is equivalent to \samp{m.__dict__["x"] = 1}.
...
@@ -514,7 +520,7 @@ e.g., \samp{m.x = 1} is equivalent to \samp{m.__dict__["x"] = 1}.
Special read-only attribute:
\member
{__
dict
__}
is the module's
Special read-only attribute:
\member
{__
dict
__}
is the module's
namespace as a dictionary object.
namespace as a dictionary object.
\
ttindex
{__
dict
__
}
\
withsubitem
{
(module attribute)
}{
\ttindex
{__
dict
__}
}
Predefined (writable) attributes:
\member
{__
name
__}
Predefined (writable) attributes:
\member
{__
name
__}
is the module's name;
\member
{__
doc
__}
is the
is the module's name;
\member
{__
doc
__}
is the
...
@@ -525,9 +531,10 @@ The \member{__file__} attribute is not present for C{} modules that are
...
@@ -525,9 +531,10 @@ The \member{__file__} attribute is not present for C{} modules that are
statically linked into the interpreter; for extension modules loaded
statically linked into the interpreter; for extension modules loaded
dynamically from a shared library, it is the pathname of the shared
dynamically from a shared library, it is the pathname of the shared
library file.
library file.
\ttindex
{__
name
__}
\withsubitem
{
(module attribute)
}{
%
\ttindex
{__
doc
__}
\ttindex
{__
name
__}
%
\ttindex
{__
file
__}
\ttindex
{__
doc
__}
%
\ttindex
{__
file
__}}
\indexii
{
module
}{
namespace
}
\indexii
{
module
}{
namespace
}
\item
[Classes]
\item
[Classes]
...
@@ -569,11 +576,12 @@ Special attributes: \member{__name__} is the class name;
...
@@ -569,11 +576,12 @@ Special attributes: \member{__name__} is the class name;
containing the base classes, in the order of their occurrence in the
containing the base classes, in the order of their occurrence in the
base class list;
\member
{__
doc
__}
is the class's documentation string,
base class list;
\member
{__
doc
__}
is the class's documentation string,
or None if undefined.
or None if undefined.
\ttindex
{__
name
__}
\withsubitem
{
(class attribute)
}{
%
\ttindex
{__
module
__}
\ttindex
{__
name
__}
%
\ttindex
{__
dict
__}
\ttindex
{__
module
__}
%
\ttindex
{__
bases
__}
\ttindex
{__
dict
__}
%
\ttindex
{__
doc
__}
\ttindex
{__
bases
__}
%
\ttindex
{__
doc
__}}
\item
[Class instances]
\item
[Class instances]
A class instance is created by calling a class object (see above).
A class instance is created by calling a class object (see above).
...
@@ -609,8 +617,9 @@ section \ref{specialnames}, ``Special method names.''
...
@@ -609,8 +617,9 @@ section \ref{specialnames}, ``Special method names.''
Special attributes:
\member
{__
dict
__}
is the attribute
Special attributes:
\member
{__
dict
__}
is the attribute
dictionary;
\member
{__
class
__}
is the instance's class.
dictionary;
\member
{__
class
__}
is the instance's class.
\ttindex
{__
dict
__}
\withsubitem
{
(instance attribute)
}{
%
\ttindex
{__
class
__}
\ttindex
{__
dict
__}
%
\ttindex
{__
class
__}}
\item
[Files]
\item
[Files]
A file object represents an open file. File objects are created by the
A file object represents an open file. File objects are created by the
...
@@ -626,11 +635,12 @@ Library Reference} for complete documentation of file objects.
...
@@ -626,11 +635,12 @@ Library Reference} for complete documentation of file objects.
\indexii
{
C
}{
language
}
\indexii
{
C
}{
language
}
\index
{
stdio
}
\index
{
stdio
}
\bifuncindex
{
open
}
\bifuncindex
{
open
}
\bifuncindex
{
popen
}
\withsubitem
{
(in module os)
}{
\ttindex
{
popen()
}}
\bifuncindex
{
makefile
}
\withsubitem
{
(socket method)
}{
\ttindex
{
makefile()
}}
\ttindex
{
stdin
}
\withsubitem
{
(in module sys)
}{
%
\ttindex
{
stdout
}
\ttindex
{
stdin
}
%
\ttindex
{
stderr
}
\ttindex
{
stdout
}
%
\ttindex
{
stderr
}}
\ttindex
{
sys.stdin
}
\ttindex
{
sys.stdin
}
\ttindex
{
sys.stdout
}
\ttindex
{
sys.stdout
}
\ttindex
{
sys.stderr
}
\ttindex
{
sys.stderr
}
...
@@ -658,26 +668,35 @@ contain no references (directly or indirectly) to mutable objects.
...
@@ -658,26 +668,35 @@ contain no references (directly or indirectly) to mutable objects.
\index
{
bytecode
}
\index
{
bytecode
}
\obindex
{
code
}
\obindex
{
code
}
Special read-only attributes:
\member
{
co
_
name
}
\ttindex
{
co
_
name
}
gives
Special read-only attributes:
\member
{
co
_
name
}
gives the function
the function name;
\member
{
co
_
argcount
}
\ttindex
{
co
_
argcount
}
name;
\member
{
co
_
argcount
}
is the number of positional arguments
is the number of positional arguments (including arguments with
(including arguments with default values);
\member
{
co
_
nlocals
}
is the
default values);
\member
{
co
_
nlocals
}
\ttindex
{
co
_
nlocals
}
is the number
number of local variables used by the function (including arguments);
of local variables used by the function (including arguments);
\member
{
co
_
varnames
}
is a tuple containing the names of the local
\member
{
co
_
varnames
}
\ttindex
{
co
_
varnames
}
is a tuple containing the
variables (starting with the argument names);
\member
{
co
_
code
}
is a
names of the local variables (starting with the argument names);
string representing the sequence of bytecode instructions;
\member
{
co
_
code
}
\ttindex
{
co
_
code
}
is a string representing the sequence
\member
{
co
_
consts
}
is a tuple containing the literals used by the
of bytecode instructions;
\member
{
co
_
consts
}
\ttindex
{
co
_
consts
}
is a
bytecode;
\member
{
co
_
names
}
is a tuple containing the names used by
tuple containing the literals used by the bytecode;
the bytecode;
\member
{
co
_
filename
}
is the filename from which the code
\member
{
co
_
names
}
\ttindex
{
co
_
names
}
is a tuple containing the names used
was compiled;
\member
{
co
_
firstlineno
}
is the first line number of the
by the bytecode;
\member
{
co
_
filename
}
\ttindex
{
co
_
filename
}
is the
function;
\member
{
co
_
lnotab
}
is a string encoding the mapping from
filename from which the code was compiled;
byte code offsets to line numbers (for detais see the source code of
\member
{
co
_
firstlineno
}
\ttindex
{
co
_
firstlineno
}
is the first line number
the interpreter);
\member
{
co
_
stacksize
}
is the required stack size
of the function;
\member
{
co
_
lnotab
}
\ttindex
{
co
_
lnotab
}
is a string
(including local variables);
\member
{
co
_
flags
}
is an integer encoding
encoding the mapping from byte code offsets to line numbers (for
a number of flags for the interpreter.
detais see the source code of the interpreter);
\withsubitem
{
(code object attribute)
}{
%
\member
{
co
_
stacksize
}
\ttindex
{
co
_
stacksize
}
is the required stack size
\ttindex
{
co
_
argcount
}
%
(including local variables);
\member
{
co
_
flags
}
\ttindex
{
co
_
flags
}
is an
\ttindex
{
co
_
code
}
%
integer encoding a number of flags for the interpreter.
\ttindex
{
co
_
consts
}
%
\ttindex
{
co
_
filename
}
%
\ttindex
{
co
_
firstlineno
}
%
\ttindex
{
co
_
flags
}
%
\ttindex
{
co
_
lnotab
}
%
\ttindex
{
co
_
name
}
%
\ttindex
{
co
_
names
}
%
\ttindex
{
co
_
nlocals
}
%
\ttindex
{
co
_
stacksize
}
%
\ttindex
{
co
_
varnames
}}
The following flag bits are defined for
\member
{
co
_
flags
}
: bit 2 is set
The following flag bits are defined for
\member
{
co
_
flags
}
: bit 2 is set
if the function uses the
\samp
{
*arguments
}
syntax to accept an
if the function uses the
\samp
{
*arguments
}
syntax to accept an
...
@@ -687,6 +706,7 @@ arguments; other bits are used internally or reserved for future use.
...
@@ -687,6 +706,7 @@ arguments; other bits are used internally or reserved for future use.
If a code object represents a function, the first item in
If a code object represents a function, the first item in
\member
{
co
_
consts
}
is the documentation string of the
\member
{
co
_
consts
}
is the documentation string of the
function, or
\code
{
None
}
if undefined.
function, or
\code
{
None
}
if undefined.
\index
{
documentation string
}
\item
[Frame objects]
\item
[Frame objects]
Frame objects represent execution frames. They may occur in traceback
Frame objects represent execution frames. They may occur in traceback
...
@@ -704,24 +724,26 @@ executing in restricted execution mode;
...
@@ -704,24 +724,26 @@ executing in restricted execution mode;
\member
{
f
_
lineno
}
gives the line number and
\member
{
f
_
lasti
}
gives the
\member
{
f
_
lineno
}
gives the line number and
\member
{
f
_
lasti
}
gives the
precise instruction (this is an index into the bytecode string of
precise instruction (this is an index into the bytecode string of
the code object).
the code object).
\ttindex
{
f
_
back
}
\withsubitem
{
(frame attribute)
}{
%
\ttindex
{
f
_
code
}
\ttindex
{
f
_
back
}
%
\ttindex
{
f
_
globals
}
\ttindex
{
f
_
code
}
%
\ttindex
{
f
_
locals
}
\ttindex
{
f
_
globals
}
%
\ttindex
{
f
_
lineno
}
\ttindex
{
f
_
locals
}
%
\ttindex
{
f
_
lasti
}
\ttindex
{
f
_
lineno
}
%
\ttindex
{
f
_
builtins
}
\ttindex
{
f
_
lasti
}
%
\ttindex
{
f
_
restricted
}
\ttindex
{
f
_
builtins
}
%
\ttindex
{
f
_
restricted
}}
Special writable attributes:
\member
{
f
_
trace
}
, if not
\code
{
None
}
, is a
Special writable attributes:
\member
{
f
_
trace
}
, if not
\code
{
None
}
, is a
function called at the start of each source code line (this is used by
function called at the start of each source code line (this is used by
the debugger);
\member
{
f
_
exc
_
type
}
,
\member
{
f
_
exc
_
value
}
,
the debugger);
\member
{
f
_
exc
_
type
}
,
\member
{
f
_
exc
_
value
}
,
\member
{
f
_
exc
_
traceback
}
represent the most recent exception caught in
\member
{
f
_
exc
_
traceback
}
represent the most recent exception caught in
this frame.
this frame.
\ttindex
{
f
_
trace
}
\withsubitem
{
(frame attribute)
}{
%
\ttindex
{
f
_
exc
_
type
}
\ttindex
{
f
_
trace
}
%
\ttindex
{
f
_
exc
_
value
}
\ttindex
{
f
_
exc
_
type
}
%
\ttindex
{
f
_
exc
_
traceback
}
\ttindex
{
f
_
exc
_
value
}
%
\ttindex
{
f
_
exc
_
traceback
}}
\item
[Traceback objects]
\label
{
traceback
}
\item
[Traceback objects]
\label
{
traceback
}
Traceback objects represent a stack trace of an exception. A
Traceback objects represent a stack trace of an exception. A
...
@@ -743,9 +765,10 @@ interactive, it is also made available to the user as
...
@@ -743,9 +765,10 @@ interactive, it is also made available to the user as
\indexii
{
stack
}{
trace
}
\indexii
{
stack
}{
trace
}
\indexii
{
exception
}{
handler
}
\indexii
{
exception
}{
handler
}
\indexii
{
execution
}{
stack
}
\indexii
{
execution
}{
stack
}
\ttindex
{
exc
_
info
}
\withsubitem
{
(in module sys)
}{
%
\ttindex
{
exc
_
traceback
}
\ttindex
{
exc
_
info
}
%
\ttindex
{
last
_
traceback
}
\ttindex
{
exc
_
traceback
}
%
\ttindex
{
last
_
traceback
}}
\ttindex
{
sys.exc
_
info
}
\ttindex
{
sys.exc
_
info
}
\ttindex
{
sys.exc
_
traceback
}
\ttindex
{
sys.exc
_
traceback
}
\ttindex
{
sys.last
_
traceback
}
\ttindex
{
sys.last
_
traceback
}
...
@@ -759,10 +782,11 @@ precise instruction. The line number and last instruction in the
...
@@ -759,10 +782,11 @@ precise instruction. The line number and last instruction in the
traceback may differ from the line number of its frame object if the
traceback may differ from the line number of its frame object if the
exception occurred in a
\keyword
{
try
}
statement with no matching
exception occurred in a
\keyword
{
try
}
statement with no matching
except clause or with a finally clause.
except clause or with a finally clause.
\ttindex
{
tb
_
next
}
\withsubitem
{
(traceback attribute)
}{
%
\ttindex
{
tb
_
frame
}
\ttindex
{
tb
_
next
}
%
\ttindex
{
tb
_
lineno
}
\ttindex
{
tb
_
frame
}
%
\ttindex
{
tb
_
lasti
}
\ttindex
{
tb
_
lineno
}
%
\ttindex
{
tb
_
lasti
}}
\stindex
{
try
}
\stindex
{
try
}
\item
[Slice objects]
\item
[Slice objects]
...
@@ -770,11 +794,15 @@ Slice objects are used to represent slices when \emph{extended slice
...
@@ -770,11 +794,15 @@ Slice objects are used to represent slices when \emph{extended slice
syntax
}
is used. This is a slice using two colons, or multiple slices
syntax
}
is used. This is a slice using two colons, or multiple slices
or ellipses separated by commas, e.g.,
\code
{
a[i:j:step]
}
,
\code
{
a[i:j,
or ellipses separated by commas, e.g.,
\code
{
a[i:j:step]
}
,
\code
{
a[i:j,
k:l]
}
, or
\code
{
a[..., i:j])
}
. They are also created by the built-in
k:l]
}
, or
\code
{
a[..., i:j])
}
. They are also created by the built-in
\function
{
slice()
}
function.
\function
{
slice()
}
\bifuncindex
{
slice
}
function.
Special read-only attributes:
\member
{
start
}
is the lowerbound;
Special read-only attributes:
\member
{
start
}
is the lowerbound;
\member
{
stop
}
is the upperbound;
\member
{
step
}
is the step value; each is
\member
{
stop
}
is the upperbound;
\member
{
step
}
is the step value; each is
\code
{
None
}
if omitted. These attributes can have any type.
\code
{
None
}
if omitted. These attributes can have any type.
\withsubitem
{
(slice object attribute)
}{
%
\ttindex
{
start
}
%
\ttindex
{
stop
}
%
\ttindex
{
step
}}
\end{description}
% Internal types
\end{description}
% Internal types
...
@@ -792,24 +820,23 @@ this class, then \code{x[i]} is equivalent to
...
@@ -792,24 +820,23 @@ this class, then \code{x[i]} is equivalent to
a list object,
\code
{
x.
__
getitem
__
(i)
}
is not equivalent to
a list object,
\code
{
x.
__
getitem
__
(i)
}
is not equivalent to
\code
{
x[i]
}
.) Except where mentioned, attempts to execute an
\code
{
x[i]
}
.) Except where mentioned, attempts to execute an
operation raise an exception when no appropriate method is defined.
operation raise an exception when no appropriate method is defined.
\
ttindex
{__
getitem
__
}
\
withsubitem
{
(mapping object method)
}{
\ttindex
{__
getitem
__
()
}
}
\subsection
{
Basic customization
\label
{
customization
}}
\subsection
{
Basic customization
\label
{
customization
}}
\begin{methoddesc
ni}
{__
init
__}{
self
\optional
{
, args...
}}
\begin{methoddesc
}
[object]
{__
init
__}{
self
\optional
{
, args...
}}
Called when the instance is created. The arguments are those passed
Called when the instance is created. The arguments are those passed
to the class constructor expression. If a base class has an
to the class constructor expression. If a base class has an
\method
{__
init
__
()
}
method the derived class's
\method
{__
init
__
()
}
method must
\method
{__
init
__
()
}
method the derived class's
\method
{__
init
__
()
}
method must
explicitly call it to ensure proper initialization of the base class
explicitly call it to ensure proper initialization of the base class
part of the instance, e.g.,
\samp
{
BaseClass.
__
init
__
(
\var
{
self
}
,
part of the instance, e.g.,
\samp
{
BaseClass.
__
init
__
(
\var
{
self
}
,
[
\var
{
args
}
...])
}
.
[
\var
{
args
}
...])
}
.
\ttindex
{__
init
__}
\indexii
{
class
}{
constructor
}
\indexii
{
class
}{
constructor
}
\end{methoddesc
ni
}
\end{methoddesc}
\begin{methoddesc
ni}
{__
del
__}{
self
}
\begin{methoddesc
}
[object]
{__
del
__}{
self
}
Called when the instance is about to be destroyed. This is also
Called when the instance is about to be destroyed. This is also
called a destructor
\index
{
destructor
}
. If a base class
called a destructor
\index
{
destructor
}
. If a base class
has a
\method
{__
del
__
()
}
method, the derived class's
\method
{__
del
__
()
}
method
has a
\method
{__
del
__
()
}
method, the derived class's
\method
{__
del
__
()
}
method
...
@@ -821,7 +848,6 @@ reference to it. It may then be called at a later time when this new
...
@@ -821,7 +848,6 @@ reference to it. It may then be called at a later time when this new
reference is deleted. It is not guaranteed that
reference is deleted. It is not guaranteed that
\method
{__
del
__
()
}
methods are called for objects that still exist when
\method
{__
del
__
()
}
methods are called for objects that still exist when
the interpreter exits.
the interpreter exits.
\ttindex
{__
del
__}
\stindex
{
del
}
\stindex
{
del
}
\strong
{
Programmer's note:
}
\samp
{
del x
}
doesn't directly call
\strong
{
Programmer's note:
}
\samp
{
del x
}
doesn't directly call
...
@@ -853,9 +879,9 @@ deleted from their module before other globals are deleted; if no
...
@@ -853,9 +879,9 @@ deleted from their module before other globals are deleted; if no
other references to such globals exist, this may help in assuring that
other references to such globals exist, this may help in assuring that
imported modules are still available at the time when the
imported modules are still available at the time when the
\method
{__
del
__
()
}
method is called.
\method
{__
del
__
()
}
method is called.
\end{methoddesc
ni
}
\end{methoddesc}
\begin{methoddesc
ni}
{__
repr
__}{
self
}
\begin{methoddesc
}
[object]
{__
repr
__}{
self
}
Called by the
\function
{
repr()
}
\bifuncindex
{
repr
}
built-in function
Called by the
\function
{
repr()
}
\bifuncindex
{
repr
}
built-in function
and by string conversions (reverse quotes) to compute the ``official''
and by string conversions (reverse quotes) to compute the ``official''
string representation of an object. This should normally look like a
string representation of an object. This should normally look like a
...
@@ -864,36 +890,33 @@ the same value. By convention, objects which cannot be trivially
...
@@ -864,36 +890,33 @@ the same value. By convention, objects which cannot be trivially
converted to strings which can be used to create a similar object
converted to strings which can be used to create a similar object
produce a string of the form
\samp
{
<
\var
{
...some useful
produce a string of the form
\samp
{
<
\var
{
...some useful
description...
}
>
}
.
description...
}
>
}
.
\ttindex
{__
repr
__}
\indexii
{
string
}{
conversion
}
\indexii
{
string
}{
conversion
}
\indexii
{
reverse
}{
quotes
}
\indexii
{
reverse
}{
quotes
}
\indexii
{
backward
}{
quotes
}
\indexii
{
backward
}{
quotes
}
\index
{
back-quotes
}
\index
{
back-quotes
}
\end{methoddesc
ni
}
\end{methoddesc}
\begin{methoddesc
ni}
{__
str
__}{
self
}
\begin{methoddesc
}
[object]
{__
str
__}{
self
}
Called by the
\function
{
str()
}
\bifuncindex
{
str
}
built-in function and
Called by the
\function
{
str()
}
\bifuncindex
{
str
}
built-in function and
by the
\keyword
{
print
}
\stindex
{
print
}
statement to compute the
by the
\keyword
{
print
}
\stindex
{
print
}
statement to compute the
``informal'' string representation of an object. This differs from
``informal'' string representation of an object. This differs from
\method
{__
repr
__
()
}
in that it does not have to be a valid Python
\method
{__
repr
__
()
}
in that it does not have to be a valid Python
expression: a more convenient or concise representation may be used
expression: a more convenient or concise representation may be used
instead.
instead.
\ttindex
{__
str
__}
\end{methoddesc}
\end{methoddescni}
\begin{methoddesc
ni}
{__
cmp
__}{
self, other
}
\begin{methoddesc
}
[object]
{__
cmp
__}{
self, other
}
Called by all comparison operations. Should return a negative integer if
Called by all comparison operations. Should return a negative integer if
\code
{
self < other
}
, zero if
\code
{
self == other
}
, a positive integer if
\code
{
self < other
}
, zero if
\code
{
self == other
}
, a positive integer if
\code
{
self > other
}
. If no
\method
{__
cmp
__
()
}
operation is defined, class
\code
{
self > other
}
. If no
\method
{__
cmp
__
()
}
operation is defined, class
instances are compared by object identity (``address'').
instances are compared by object identity (``address'').
(Note: the restriction that exceptions are not propagated by
(Note: the restriction that exceptions are not propagated by
\method
{__
cmp
__
()
}
has been removed in Python 1.5.)
\method
{__
cmp
__
()
}
has been removed in Python 1.5.)
\ttindex
{__
cmp
__}
\bifuncindex
{
cmp
}
\bifuncindex
{
cmp
}
\index
{
comparisons
}
\index
{
comparisons
}
\end{methoddesc
ni
}
\end{methoddesc}
\begin{methoddesc
ni}
{__
hash
__}{
self
}
\begin{methoddesc
}
[object]
{__
hash
__}{
self
}
Called for the key object for dictionary
\obindex
{
dictionary
}
Called for the key object for dictionary
\obindex
{
dictionary
}
operations, and by the built-in function
operations, and by the built-in function
\function
{
hash()
}
\bifuncindex
{
hash
}
. Should return a 32-bit integer
\function
{
hash()
}
\bifuncindex
{
hash
}
. Should return a 32-bit integer
...
@@ -910,18 +933,17 @@ implements a \method{__cmp__()} method it should not implement
...
@@ -910,18 +933,17 @@ implements a \method{__cmp__()} method it should not implement
\method
{__
hash
__
()
}
, since the dictionary implementation requires that
\method
{__
hash
__
()
}
, since the dictionary implementation requires that
a key's hash value is immutable (if the object's hash value changes, it
a key's hash value is immutable (if the object's hash value changes, it
will be in the wrong hash bucket).
will be in the wrong hash bucket).
\ttindex
{__
cmp
__}
\withsubitem
{
(object method)
}{
\ttindex
{__
cmp
__
()
}}
\ttindex
{__
hash
__}
\end{methoddesc}
\end{methoddescni}
\begin{methoddesc
ni}
{__
nonzero
__}{
self
}
\begin{methoddesc
}
[object]
{__
nonzero
__}{
self
}
Called to implement truth value testing; should return
\code
{
0
}
or
Called to implement truth value testing; should return
\code
{
0
}
or
\code
{
1
}
. When this method is not defined,
\method
{__
len
__
()
}
is
\code
{
1
}
. When this method is not defined,
\method
{__
len
__
()
}
is
called, if it is defined (see below). If a class defines neither
called, if it is defined (see below). If a class defines neither
\method
{__
len
__
()
}
nor
\method
{__
nonzero
__
()
}
, all its instances are
\method
{__
len
__
()
}
nor
\method
{__
nonzero
__
()
}
, all its instances are
considered true.
considered true.
\
ttindex
{__
nonzero
__
}
\
withsubitem
{
(mapping object method)
}{
\ttindex
{__
len
__
()
}
}
\end{methoddesc
ni
}
\end{methoddesc}
\subsection
{
Customizing attribute access
\label
{
attribute-access
}}
\subsection
{
Customizing attribute access
\label
{
attribute-access
}}
...
@@ -933,13 +955,12 @@ For performance reasons, these methods are cached in the class object
...
@@ -933,13 +955,12 @@ For performance reasons, these methods are cached in the class object
at class definition time; therefore, they cannot be changed after the
at class definition time; therefore, they cannot be changed after the
class definition is executed.
class definition is executed.
\begin{methoddesc
ni}
{__
getattr
__}{
self, name
}
\begin{methoddesc
}
[object]
{__
getattr
__}{
self, name
}
Called when an attribute lookup has not found the attribute in the
Called when an attribute lookup has not found the attribute in the
usual places (i.e. it is not an instance attribute nor is it found in
usual places (i.e. it is not an instance attribute nor is it found in
the class tree for
\code
{
self
}
).
\code
{
name
}
is the attribute name.
the class tree for
\code
{
self
}
).
\code
{
name
}
is the attribute name.
This method should return the (computed) attribute value or raise an
This method should return the (computed) attribute value or raise an
\exception
{
AttributeError
}
exception.
\exception
{
AttributeError
}
exception.
\ttindex
{__
getattr
__}
Note that if the attribute is found through the normal mechanism,
Note that if the attribute is found through the normal mechanism,
\method
{__
getattr
__
()
}
is not called. (This is an intentional
\method
{__
getattr
__
()
}
is not called. (This is an intentional
...
@@ -950,40 +971,38 @@ the instance.
...
@@ -950,40 +971,38 @@ the instance.
Note that at least for instance variables, you can fake
Note that at least for instance variables, you can fake
total control by not inserting any values in the instance
total control by not inserting any values in the instance
attribute dictionary (but instead inserting them in another object).
attribute dictionary (but instead inserting them in another object).
\
ttindex
{__
setattr
__
}
\
withsubitem
{
(object method)
}{
\ttindex
{__
setattr
__
()
}
}
\end{methoddesc
ni
}
\end{methoddesc}
\begin{methoddesc
ni}
{__
setattr
__}{
self, name, value
}
\begin{methoddesc
}
[object]
{__
setattr
__}{
self, name, value
}
Called when an attribute assignment is attempted. This is called
Called when an attribute assignment is attempted. This is called
instead of the normal mechanism (i.e.
\
store the value in the instance
instead of the normal mechanism (i.e.
\
store the value in the instance
dictionary).
\var
{
name
}
is the attribute name,
\var
{
value
}
is the
dictionary).
\var
{
name
}
is the attribute name,
\var
{
value
}
is the
value to be assigned to it.
value to be assigned to it.
\ttindex
{__
setattr
__}
If
\method
{__
setattr
__
()
}
wants to assign to an instance attribute, it
If
\method
{__
setattr
__
()
}
wants to assign to an instance attribute, it
should not simply execute
\samp
{
self.
\var
{
name
}
= value
}
--- this
should not simply execute
\samp
{
self.
\var
{
name
}
= value
}
--- this
would cause a recursive call to itself. Instead, it should insert the
would cause a recursive call to itself. Instead, it should insert the
value in the dictionary of instance attributes, e.g.,
value in the dictionary of instance attributes, e.g.,
\samp
{
self.
__
dict
__
[
\var
{
name
}
] = value
}
.
\samp
{
self.
__
dict
__
[
\var
{
name
}
] = value
}
.
\
ttindex
{__
dict
__
}
\
withsubitem
{
(instance attribute)
}{
\ttindex
{__
dict
__}
}
\end{methoddesc
ni
}
\end{methoddesc}
\begin{methoddesc
ni}
{__
delattr
__}{
self, name
}
\begin{methoddesc
}
[object]
{__
delattr
__}{
self, name
}
Like
\method
{__
setattr
__
()
}
but for attribute deletion instead of
Like
\method
{__
setattr
__
()
}
but for attribute deletion instead of
assignment.
assignment.
This should only be implemented if
\samp
{
del
\ttindex
{__
delattr
__}
obj.
\var
{
name
}}
is meaningful for the object.
\end{methoddesc
ni
}
\end{methoddesc}
\subsection
{
Emulating callable objects
\label
{
callable-types
}}
\subsection
{
Emulating callable objects
\label
{
callable-types
}}
\begin{methoddesc
ni}
{__
call
__}{
self
\optional
{
, args...
}}
\begin{methoddesc
}
[object]
{__
call
__}{
self
\optional
{
, args...
}}
Called when the instance is ``called'' as a function; if this method
Called when the instance is ``called'' as a function; if this method
is defined,
\code
{
\var
{
x
}
(arg1, arg2, ...)
}
is a shorthand for
is defined,
\code
{
\var
{
x
}
(arg1, arg2, ...)
}
is a shorthand for
\code
{
\var
{
x
}
.
__
call
__
(arg1, arg2, ...)
}
.
\code
{
\var
{
x
}
.
__
call
__
(arg1, arg2, ...)
}
.
\ttindex
{__
call
__}
\indexii
{
call
}{
instance
}
\indexii
{
call
}{
instance
}
\end{methoddesc
ni
}
\end{methoddesc}
\subsection
{
Emulating sequence and mapping types
\label
{
sequence-types
}}
\subsection
{
Emulating sequence and mapping types
\label
{
sequence-types
}}
...
@@ -1007,57 +1026,60 @@ multiplication (meaning repetition) by defining the methods
...
@@ -1007,57 +1026,60 @@ multiplication (meaning repetition) by defining the methods
\method
{__
add
__
()
}
,
\method
{__
radd
__
()
}
,
\method
{__
mul
__
()
}
and
\method
{__
add
__
()
}
,
\method
{__
radd
__
()
}
,
\method
{__
mul
__
()
}
and
\method
{__
rmul
__
()
}
described below; they should not define
\method
{__
rmul
__
()
}
described below; they should not define
\method
{__
coerce
__
()
}
or other numerical operators.
\method
{__
coerce
__
()
}
or other numerical operators.
\ttindex
{
keys
}
\withsubitem
{
(mapping object method)
}{
%
\ttindex
{
values
}
\ttindex
{
keys()
}
%
\ttindex
{
items
}
\ttindex
{
values()
}
%
\ttindex
{
has
_
key
}
\ttindex
{
items()
}
%
\ttindex
{
get
}
\ttindex
{
has
_
key()
}
%
\ttindex
{
clear
}
\ttindex
{
get()
}
%
\ttindex
{
copy
}
\ttindex
{
clear()
}
%
\ttindex
{
update
}
\ttindex
{
copy()
}
%
\ttindex
{
append
}
\ttindex
{
update()
}}
\ttindex
{
count
}
\withsubitem
{
(sequence object method)
}{
%
\ttindex
{
index
}
\ttindex
{
append()
}
%
\ttindex
{
insert
}
\ttindex
{
count()
}
%
\ttindex
{
pop
}
\ttindex
{
index()
}
%
\ttindex
{
remove
}
\ttindex
{
insert()
}
%
\ttindex
{
reverse
}
\ttindex
{
pop()
}
%
\ttindex
{
sort
}
\ttindex
{
remove()
}
%
\ttindex
{__
add
__}
\ttindex
{
reverse()
}
%
\ttindex
{__
radd
__}
\ttindex
{
sort()
}
%
\ttindex
{__
mul
__}
\ttindex
{__
add
__
()
}
%
\ttindex
{__
rmul
__}
\ttindex
{__
radd
__
()
}
%
\ttindex
{__
coerce
__}
\ttindex
{__
mul
__
()
}
%
\ttindex
{__
rmul
__
()
}}
\begin{methoddescni}
{__
len
__}{
self
}
\withsubitem
{
(numberic object method)
}{
\ttindex
{__
coerce
__
()
}}
\begin{methoddesc}
[mapping object]
{__
len
__}{
self
}
Called to implement the built-in function
Called to implement the built-in function
\function
{
len()
}
\bifuncindex
{
len
}
. Should return the length of the
\function
{
len()
}
\bifuncindex
{
len
}
. Should return the length of the
object, an integer
\code
{
>=
}
0. Also, an object that doesn't define a
object, an integer
\code
{
>=
}
0. Also, an object that doesn't define a
\method
{__
nonzero
__
()
}
method and whose
\method
{__
len
__
()
}
method
\method
{__
nonzero
__
()
}
method and whose
\method
{__
len
__
()
}
method
returns zero is considered to be false in a Boolean context.
returns zero is considered to be false in a Boolean context.
\ttindex
{__
len
__}
\withsubitem
{
(object method)
}{
\ttindex
{__
nonzero
__
()
}}
\ttindex
{__
nonzero
__}
\end{methoddesc}
\end{methoddescni}
\begin{methoddesc
ni}
{__
getitem
__}{
self, key
}
\begin{methoddesc
}
[mapping object]
{__
getitem
__}{
self, key
}
Called to implement evaluation of
\code
{
\var
{
self
}
[
\var
{
key
}
]
}
.
Called to implement evaluation of
\code
{
\var
{
self
}
[
\var
{
key
}
]
}
.
For a sequence types, the accepted keys should be integers. Note that the
For a sequence types, the accepted keys should be integers. Note that the
special interpretation of negative indices (if the class wishes to
special interpretation of negative indices (if the class wishes to
emulate a sequence type) is up to the
\method
{__
getitem
__
()
}
method.
emulate a sequence type) is up to the
\method
{__
getitem
__
()
}
method.
\ttindex
{__
getitem
__}
\end{methoddesc}
\end{methoddescni}
\begin{methoddesc
ni}
{__
setitem
__}{
self, key, value
}
\begin{methoddesc
}
[mapping object]
{__
setitem
__}{
self, key, value
}
Called to implement assignment to
\code
{
\var
{
self
}
[
\var
{
key
}
]
}
. Same
Called to implement assignment to
\code
{
\var
{
self
}
[
\var
{
key
}
]
}
. Same
note as for
\method
{__
getitem
__
()
}
.
note as for
\method
{__
getitem
__
()
}
. This should only be implemented
\ttindex
{__
setitem
__}
for mappings if the objects support changes to the values for keys, or
\end{methoddescni}
if new keys can be added, or for sequences if elements can be
replaced.
\end{methoddesc}
\begin{methoddesc
ni}
{__
delitem
__}{
self, key
}
\begin{methoddesc
}
[mapping object]
{__
delitem
__}{
self, key
}
Called to implement deletion of
\code
{
\var
{
self
}
[
\var
{
key
}
]
}
. Same
Called to implement deletion of
\code
{
\var
{
self
}
[
\var
{
key
}
]
}
. Same
note as for
\method
{__
getitem
__
()
}
.
note as for
\method
{__
getitem
__
()
}
. This should only be implemented
\ttindex
{__
delitem
__}
for mappings if the objects support removal of keys, or for sequences
\end{methoddescni}
if elements can be removed from the sequence.
\end{methoddesc}
\subsection
{
Additional methods for emulation of sequence types
\subsection
{
Additional methods for emulation of sequence types
...
@@ -1068,7 +1090,7 @@ objects. Immutable sequences methods should only define
...
@@ -1068,7 +1090,7 @@ objects. Immutable sequences methods should only define
\method
{__
getslice
__
()
}
; mutable sequences, should define all three
\method
{__
getslice
__
()
}
; mutable sequences, should define all three
three methods.
three methods.
\begin{methoddesc
ni}
{__
getslice
__}{
self, i, j
}
\begin{methoddesc
}
[sequence object]
{__
getslice
__}{
self, i, j
}
Called to implement evaluation of
\code
{
\var
{
self
}
[
\var
{
i
}
:
\var
{
j
}
]
}
.
Called to implement evaluation of
\code
{
\var
{
self
}
[
\var
{
i
}
:
\var
{
j
}
]
}
.
The returned object should be of the same type as
\var
{
self
}
. Note
The returned object should be of the same type as
\var
{
self
}
. Note
that missing
\var
{
i
}
or
\var
{
j
}
in the slice expression are replaced
that missing
\var
{
i
}
or
\var
{
j
}
in the slice expression are replaced
...
@@ -1076,20 +1098,17 @@ by zero or \code{sys.maxint}, respectively, and no further
...
@@ -1076,20 +1098,17 @@ by zero or \code{sys.maxint}, respectively, and no further
transformations on the indices is performed. The interpretation of
transformations on the indices is performed. The interpretation of
negative indices and indices larger than the length of the sequence is
negative indices and indices larger than the length of the sequence is
up to the method.
up to the method.
\ttindex
{__
getslice
__}
\end{methoddesc}
\end{methoddescni}
\begin{methoddesc
ni}
{__
setslice
__}{
self, i, j, sequence
}
\begin{methoddesc
}
[sequence object]
{__
setslice
__}{
self, i, j, sequence
}
Called to implement assignment to
\code
{
\var
{
self
}
[
\var
{
i
}
:
\var
{
j
}
]
}
.
Called to implement assignment to
\code
{
\var
{
self
}
[
\var
{
i
}
:
\var
{
j
}
]
}
.
Same notes for
\var
{
i
}
and
\var
{
j
}
as for
\method
{__
getslice
__
()
}
.
Same notes for
\var
{
i
}
and
\var
{
j
}
as for
\method
{__
getslice
__
()
}
.
\ttindex
{__
setslice
__}
\end{methoddesc}
\end{methoddescni}
\begin{methoddesc
ni}
{__
delslice
__}{
self, i, j
}
\begin{methoddesc
}
[sequence object]
{__
delslice
__}{
self, i, j
}
Called to implement deletion of
\code
{
\var
{
self
}
[
\var
{
i
}
:
\var
{
j
}
]
}
.
Called to implement deletion of
\code
{
\var
{
self
}
[
\var
{
i
}
:
\var
{
j
}
]
}
.
Same notes for
\var
{
i
}
and
\var
{
j
}
as for
\method
{__
getslice
__
()
}
.
Same notes for
\var
{
i
}
and
\var
{
j
}
as for
\method
{__
getslice
__
()
}
.
\ttindex
{__
delslice
__}
\end{methoddesc}
\end{methoddescni}
Notice that these methods are only invoked when a single slice with a
Notice that these methods are only invoked when a single slice with a
single colon is used. For slice operations involving extended slice
single colon is used. For slice operations involving extended slice
...
@@ -1103,18 +1122,18 @@ Methods corresponding to operations that are not supported by the
...
@@ -1103,18 +1122,18 @@ Methods corresponding to operations that are not supported by the
particular kind of number implemented (e.g., bitwise operations for
particular kind of number implemented (e.g., bitwise operations for
non-integral numbers) should be left undefined.
non-integral numbers) should be left undefined.
\begin{methoddesc
ni}
{__
add
__}{
self, other
}
\begin{methoddesc
}
[numberic interface]
{__
add
__}{
self, other
}
\methodline
ni
{__
sub
__}{
self, other
}
\methodline
{__
sub
__}{
self, other
}
\methodline
ni
{__
mul
__}{
self, other
}
\methodline
{__
mul
__}{
self, other
}
\methodline
ni
{__
div
__}{
self, other
}
\methodline
{__
div
__}{
self, other
}
\methodline
ni
{__
mod
__}{
self, other
}
\methodline
{__
mod
__}{
self, other
}
\methodline
ni
{__
divmod
__}{
self, other
}
\methodline
{__
divmod
__}{
self, other
}
\methodline
ni
{__
pow
__}{
self, other
\optional
{
, modulo
}}
\methodline
{__
pow
__}{
self, other
\optional
{
, modulo
}}
\methodline
ni
{__
lshift
__}{
self, other
}
\methodline
{__
lshift
__}{
self, other
}
\methodline
ni
{__
rshift
__}{
self, other
}
\methodline
{__
rshift
__}{
self, other
}
\methodline
ni
{__
and
__}{
self, other
}
\methodline
{__
and
__}{
self, other
}
\methodline
ni
{__
xor
__}{
self, other
}
\methodline
{__
xor
__}{
self, other
}
\methodline
ni
{__
or
__}{
self, other
}
\methodline
{__
or
__}{
self, other
}
These functions are
These functions are
called to implement the binary arithmetic operations (
\code
{
+
}
,
called to implement the binary arithmetic operations (
\code
{
+
}
,
\code
{
-
}
,
\code
{
*
}
,
\code
{
/
}
,
\code
{
\%
}
,
\code
{
-
}
,
\code
{
*
}
,
\code
{
/
}
,
\code
{
\%
}
,
...
@@ -1127,32 +1146,20 @@ class that has an \method{__add__()} method,
...
@@ -1127,32 +1146,20 @@ class that has an \method{__add__()} method,
\method
{__
pow
__
()
}
should be defined to accept an optional third
\method
{__
pow
__
()
}
should be defined to accept an optional third
argument if the ternary version of the built-in
argument if the ternary version of the built-in
\function
{
pow()
}
\bifuncindex
{
pow
}
function is to be supported.
\function
{
pow()
}
\bifuncindex
{
pow
}
function is to be supported.
\ttindex
{__
or
__}
\end{methoddesc}
\ttindex
{__
xor
__}
\ttindex
{__
and
__}
\begin{methoddesc}
[numeric interface]
{__
radd
__}{
self, other
}
\ttindex
{__
rshift
__}
\methodline
{__
rsub
__}{
self, other
}
\ttindex
{__
lshift
__}
\methodline
{__
rmul
__}{
self, other
}
\ttindex
{__
pow
__}
\methodline
{__
rdiv
__}{
self, other
}
\ttindex
{__
divmod
__}
\methodline
{__
rmod
__}{
self, other
}
\ttindex
{__
mod
__}
\methodline
{__
rdivmod
__}{
self, other
}
\ttindex
{__
div
__}
\methodline
{__
rpow
__}{
self, other
}
\ttindex
{__
mul
__}
\methodline
{__
rlshift
__}{
self, other
}
\ttindex
{__
sub
__}
\methodline
{__
rrshift
__}{
self, other
}
\ttindex
{__
add
__}
\methodline
{__
rand
__}{
self, other
}
\end{methoddescni}
\methodline
{__
rxor
__}{
self, other
}
\methodline
{__
ror
__}{
self, other
}
\begin{methoddescni}
{__
radd
__}{
self, other
}
\methodlineni
{__
rsub
__}{
self, other
}
\methodlineni
{__
rmul
__}{
self, other
}
\methodlineni
{__
rdiv
__}{
self, other
}
\methodlineni
{__
rmod
__}{
self, other
}
\methodlineni
{__
rdivmod
__}{
self, other
}
\methodlineni
{__
rpow
__}{
self, other
}
\methodlineni
{__
rlshift
__}{
self, other
}
\methodlineni
{__
rrshift
__}{
self, other
}
\methodlineni
{__
rand
__}{
self, other
}
\methodlineni
{__
rxor
__}{
self, other
}
\methodlineni
{__
ror
__}{
self, other
}
These functions are
These functions are
called to implement the binary arithmetic operations (
\code
{
+
}
,
called to implement the binary arithmetic operations (
\code
{
+
}
,
\code
{
-
}
,
\code
{
*
}
,
\code
{
/
}
,
\code
{
\%
}
,
\code
{
-
}
,
\code
{
*
}
,
\code
{
/
}
,
\code
{
\%
}
,
...
@@ -1166,55 +1173,33 @@ has an \method{__rsub__()} method, \code{\var{y}.__rsub__(\var{x})} is
...
@@ -1166,55 +1173,33 @@ has an \method{__rsub__()} method, \code{\var{y}.__rsub__(\var{x})} is
called. Note that ternary
\function
{
pow()
}
\bifuncindex
{
pow
}
will not
called. Note that ternary
\function
{
pow()
}
\bifuncindex
{
pow
}
will not
try calling
\method
{__
rpow
__
()
}
(the coercion rules would become too
try calling
\method
{__
rpow
__
()
}
(the coercion rules would become too
complicated).
complicated).
\ttindex
{__
or
__}
\end{methoddesc}
\ttindex
{__
xor
__}
\ttindex
{__
and
__}
\begin{methoddesc}
[numeric interface]
{__
neg
__}{
self
}
\ttindex
{__
rshift
__}
\methodline
{__
pos
__}{
self
}
\ttindex
{__
lshift
__}
\methodline
{__
abs
__}{
self
}
\ttindex
{__
pow
__}
\methodline
{__
invert
__}{
self
}
\ttindex
{__
divmod
__}
\ttindex
{__
mod
__}
\ttindex
{__
div
__}
\ttindex
{__
mul
__}
\ttindex
{__
sub
__}
\ttindex
{__
add
__}
\end{methoddescni}
\begin{methoddescni}
{__
neg
__}{
self
}
\methodlineni
{__
pos
__}{
self
}
\methodlineni
{__
abs
__}{
self
}
\methodlineni
{__
invert
__}{
self
}
Called to implement the unary arithmetic operations (
\code
{
-
}
,
\code
{
+
}
,
Called to implement the unary arithmetic operations (
\code
{
-
}
,
\code
{
+
}
,
\function
{
abs()
}
\bifuncindex
{
abs
}
and
\code
{
~
}
).
\function
{
abs()
}
\bifuncindex
{
abs
}
and
\code
{
~
}
).
\ttindex
{__
invert
__}
\end{methoddesc}
\ttindex
{__
abs
__}
\ttindex
{__
pos
__}
\ttindex
{__
neg
__}
\end{methoddescni}
\begin{methoddesc
ni}
{__
int
__}{
self
}
\begin{methoddesc
}
[numeric interface]
{__
int
__}{
self
}
\methodlineni
{__
long
__}{
self
}
\methodlineni
{__
long
__}{
self
}
\methodlineni
{__
float
__}{
self
}
\methodlineni
{__
float
__}{
self
}
Called to implement the built-in functions
Called to implement the built-in functions
\function
{
int()
}
\bifuncindex
{
int
}
,
\function
{
long()
}
\bifuncindex
{
long
}
\function
{
int()
}
\bifuncindex
{
int
}
,
\function
{
long()
}
\bifuncindex
{
long
}
and
\function
{
float()
}
\bifuncindex
{
float
}
. Should return a value of
and
\function
{
float()
}
\bifuncindex
{
float
}
. Should return a value of
the appropriate type.
the appropriate type.
\ttindex
{__
float
__}
\end{methoddesc}
\ttindex
{__
long
__}
\ttindex
{__
int
__}
\end{methoddescni}
\begin{methoddesc
ni}
{__
oct
__}{
self
}
\begin{methoddesc
}
[numeric interface]
{__
oct
__}{
self
}
\methodlineni
{__
hex
__}{
self
}
\methodlineni
{__
hex
__}{
self
}
Called to implement the built-in functions
Called to implement the built-in functions
\function
{
oct()
}
\bifuncindex
{
oct
}
and
\function
{
oct()
}
\bifuncindex
{
oct
}
and
\function
{
hex()
}
\bifuncindex
{
hex
}
. Should return a string value.
\function
{
hex()
}
\bifuncindex
{
hex
}
. Should return a string value.
\ttindex
{__
hex
__}
\end{methoddesc}
\ttindex
{__
oct
__}
\end{methoddescni}
\begin{methoddescni}
{__
coerce
__}{
self, other
}
\begin{methoddesc}
[numeric interface]
{__
coerce
__}{
self, other
}
\ttindex
{__
coerce
__}
Called to implement ``mixed-mode'' numeric arithmetic. Should either
Called to implement ``mixed-mode'' numeric arithmetic. Should either
return a 2-tuple containing
\var
{
self
}
and
\var
{
other
}
converted to
return a 2-tuple containing
\var
{
self
}
and
\var
{
other
}
converted to
a common numeric type, or
\code
{
None
}
if conversion is possible. When
a common numeric type, or
\code
{
None
}
if conversion is possible. When
...
@@ -1223,7 +1208,7 @@ return \code{None}, since the interpreter will also ask the other
...
@@ -1223,7 +1208,7 @@ return \code{None}, since the interpreter will also ask the other
object to attempt a coercion (but sometimes, if the implementation of
object to attempt a coercion (but sometimes, if the implementation of
the other type cannot be changed, it is useful to do the conversion to
the other type cannot be changed, it is useful to do the conversion to
the other type here).
the other type here).
\end{methoddesc
ni
}
\end{methoddesc}
\strong
{
Coercion rules
}
: to evaluate
\var
{
x
}
\var
{
op
}
\var
{
y
}
, the
\strong
{
Coercion rules
}
: to evaluate
\var
{
x
}
\var
{
op
}
\var
{
y
}
, the
following steps are taken (where
\method
{__
op
__
()
}
and
following steps are taken (where
\method
{__
op
__
()
}
and
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment