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
d2a59a22
Commit
d2a59a22
authored
Mar 21, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added index entries for __*__ identifiers
parent
928ef458
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
130 additions
and
0 deletions
+130
-0
Doc/ref/ref3.tex
Doc/ref/ref3.tex
+58
-0
Doc/ref/ref4.tex
Doc/ref/ref4.tex
+6
-0
Doc/ref/ref8.tex
Doc/ref/ref8.tex
+1
-0
Doc/ref3.tex
Doc/ref3.tex
+58
-0
Doc/ref4.tex
Doc/ref4.tex
+6
-0
Doc/ref8.tex
Doc/ref8.tex
+1
-0
No files found.
Doc/ref/ref3.tex
View file @
d2a59a22
...
...
@@ -585,6 +585,7 @@ method named \verb@__getitem__@, and \verb@x@ is an instance of this
class, then
\verb
@
x[i]
@
is equivalent to
\verb
@
x.__getitem__(i)
@
.
(The reverse is not true --- if
\verb
@
x
@
is a list object,
\verb
@
x.__getitem__(i)
@
is not equivalent to
\verb
@
x[i]
@
.)
\ttindex
{__
getitem
__}
Except for
\verb
@
__repr__
@
,
\verb
@
__str__
@
and
\verb
@
__cmp__
@
,
attempts to execute an
...
...
@@ -594,6 +595,9 @@ object's class and address.
For
\verb
@
__cmp__
@
, the default is to compare instances based on their
address.
For
\verb
@
__str__
@
, the default is to use
\verb
@
__repr__
@
.
\ttindex
{__
repr
__}
\ttindex
{__
str
__}
\ttindex
{__
cmp
__}
\subsection
{
Special methods for any type
}
...
...
@@ -606,6 +610,9 @@ to the class constructor expression. If a base class has an
\code
{__
init
__}
method the derived class's
\code
{__
init
__}
method must
explicitly call it to ensure proper initialization of the base class
part of the instance.
\ttindex
{__
init
__}
\indexii
{
class
}{
constructor
}
\item
[{\tt __del__(self)}]
Called when the instance is about to be destroyed. If a base class
...
...
@@ -617,6 +624,8 @@ reference to it. It may then be called at a later time when this new
reference is deleted. It is not guaranteed that
\code
{__
del
__}
methods are called for objects that still exist when
the interpreter exits.
\ttindex
{__
del
__}
\stindex
{
del
}
Note that
\code
{
del x
}
doesn't directly call
\code
{
x.
__
del
__}
--- the
former decrements the reference count for
\code
{
x
}
by one, but
...
...
@@ -625,6 +634,8 @@ former decrements the reference count for \code{x} by one, but
\item
[{\tt __repr__(self)}]
Called by the
\verb
@
repr()
@
built-in function and by string conversions
(reverse or backward quotes) to compute the string representation of an object.
\ttindex
{__
repr
__}
\bifuncindex
{
repr
}
\indexii
{
string
}{
conversion
}
\indexii
{
reverse
}{
quotes
}
\indexii
{
backward
}{
quotes
}
...
...
@@ -633,6 +644,9 @@ Called by the \verb@repr()@ built-in function and by string conversions
\item
[{\tt __str__(self)}]
Called by the
\verb
@
str()
@
built-in function and by the
\verb
@
print
@
statement compute the string representation of an object.
\ttindex
{__
str
__}
\bifuncindex
{
str
}
\stindex
{
print
}
\item
[{\tt __cmp__(self, other)}]
Called by all comparison operations. Should return -1 if
...
...
@@ -642,6 +656,9 @@ instances are compared by object identity (``address'').
(Implementation note: due to limitations in the interpreter,
exceptions raised by comparisons are ignored, and the objects will be
considered equal in this case.)
\ttindex
{__
cmp
__}
\bifuncindex
{
cmp
}
\index
{
comparisons
}
\item
[{\tt __hash__(self)}]
Called for the key object for dictionary operations,
...
...
@@ -659,9 +676,14 @@ implements a \code{__cmp__} method it should not implement
\code
{__
hash
__}
, since the dictionary implementation assumes that a
key's hash value is a constant.
\obindex
{
dictionary
}
\ttindex
{__
cmp
__}
\ttindex
{__
hash
__}
\bifuncindex
{
hash
}
\item
[{\tt __call__(self, *args)}]
Called when the instance is ``called'' as a function.
\ttindex
{__
call
__}
\indexii
{
call
}{
instance
}
\end{description}
...
...
@@ -677,6 +699,7 @@ access for class instances.
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
the class tree for
\code
{
self
}
).
\code
{
name
}
is the attribute name.
\ttindex
{__
getattr
__}
Note that if the attribute is found through the normal mechanism,
\code
{__
getattr
__}
is not called. (This is an asymmetry between
...
...
@@ -687,22 +710,26 @@ instance.
Note that at least for instance variables,
\code
{__
getattr
__}
can fake
total control by simply not inserting any values in the instance
attribute dictionary.
\ttindex
{__
setattr
__}
\item
[{\tt __setattr__(self, name, value)}]
Called when an attribute assignment is attempted. This is called
instead of the normal mechanism (i.e. store the value as an instance
attribute).
\code
{
name
}
is the attribute name,
\code
{
value
}
is the
value to be assigned to it.
\ttindex
{__
setattr
__}
If
\code
{__
setattr
__}
wants to assign to an instance attribute, it
should not simply execute
\code
{
self.
\var
{
name
}
= value
}
--- this would
cause a recursive call. Instead, it should insert the value in the
dictionary of instance attributes, e.g.
\code
{
self.
__
dict
__
[name] =
value
}
.
\ttindex
{__
dict
__}
\item
[{\tt __delattr__(self, name)}]
Like
\code
{__
setattr
__}
but for attribute deletion instead of
assignment.
\ttindex
{__
delattr
__}
\end{description}
...
...
@@ -716,19 +743,23 @@ Called to implement the built-in function \verb@len()@. Should return
the length of the object, an integer
\verb
@
>=
@
0. Also, an object
whose
\verb
@
__len__()
@
method returns 0 is considered to be false in a
Boolean context.
\ttindex
{__
len
__}
\item
[{\tt __getitem__(self, key)}]
Called to implement evaluation of
\verb
@
self[key]
@
. Note that the
special interpretation of negative keys (if the class wishes to
emulate a sequence type) is up to the
\verb
@
__getitem__
@
method.
\ttindex
{__
getitem
__}
\item
[{\tt __setitem__(self, key, value)}]
Called to implement assignment to
\verb
@
self[key]
@
. Same note as for
\verb
@
__getitem__
@
.
\ttindex
{__
setitem
__}
\item
[{\tt __delitem__(self, key)}]
Called to implement deletion of
\verb
@
self[key]
@
. Same note as for
\verb
@
__getitem__
@
.
\ttindex
{__
delitem
__}
\end{description}
...
...
@@ -743,14 +774,17 @@ Called to implement evaluation of \verb@self[i:j]@. Note that missing
respectively, and
\verb
@
len(self)
@
has been added (once) to originally
negative
\verb
@
i
@
or
\verb
@
j
@
by the time this function is called
(unlike for
\verb
@
__getitem__
@
).
\ttindex
{__
getslice
__}
\item
[{\tt __setslice__(self, i, j, sequence)}]
Called to implement assignment to
\verb
@
self[i:j]
@
. Same notes as for
\verb
@
__getslice__
@
.
\ttindex
{__
setslice
__}
\item
[{\tt __delslice__(self, i, j)}]
Called to implement deletion of
\verb
@
self[i:j]
@
. Same notes as for
\verb
@
__getslice__
@
.
\ttindex
{__
delslice
__}
\end{description}
...
...
@@ -774,6 +808,18 @@ Called to implement deletion of \verb@self[i:j]@. Same notes as for
Called to implement the binary arithmetic operations (
\verb
@
+
@
,
\verb
@
-
@
,
\verb
@
*
@
,
\verb
@
/
@
,
\verb
@
%
@
,
\verb
@
divmod()
@
,
\verb
@
pow()
@
,
\verb
@
<<
@
,
\verb
@
>>
@
,
\verb
@
&
@
,
\verb
@
^
@
,
\verb
@
|
@
).
\ttindex
{__
or
__}
\ttindex
{__
xor
__}
\ttindex
{__
and
__}
\ttindex
{__
rshift
__}
\ttindex
{__
lshift
__}
\ttindex
{__
pow
__}
\ttindex
{__
divmod
__}
\ttindex
{__
mod
__}
\ttindex
{__
div
__}
\ttindex
{__
mul
__}
\ttindex
{__
sub
__}
\ttindex
{__
add
__}
\item
[{\tt __neg__(self)}]
\itemjoin
\item
[{\tt __pos__(self)}]
\itemjoin
...
...
@@ -781,10 +827,15 @@ Called to implement the binary arithmetic operations (\verb@+@,
\item
[{\tt __invert__(self)}]
\itembreak
Called to implement the unary arithmetic operations (
\verb
@
-
@
,
\verb
@
+
@
,
\verb
@
abs()
@
and
\verb
@
~
@
).
\ttindex
{__
invert
__}
\ttindex
{__
abs
__}
\ttindex
{__
pos
__}
\ttindex
{__
neg
__}
\item
[{\tt __nonzero__(self)}]
Called to implement boolean testing; should return 0 or 1. An
alternative name for this method is
\verb
@
__len__
@
.
\ttindex
{__
nonzero
__}
\item
[{\tt __coerce__(self, other)}]
Called to implement ``mixed-mode'' numeric arithmetic. Should either
...
...
@@ -794,6 +845,7 @@ would be the type of other, it is sufficient to return None, since the
interpreter will also ask the other 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 here).
\ttindex
{__
coerce
__}
Note that this method is not called to coerce the arguments to
\verb
@
+
@
and
\verb
@
*
@
, because these are also used to implement sequence
...
...
@@ -803,16 +855,22 @@ same reason, in \verb@n*x@, where \verb@n@ is a built-in number and
\footnote
{
The interpreter should really distinguish between
user-defined classes implementing sequences, mappings or numbers, but
currently it doesn't --- hence this strange exception.
}
\ttindex
{__
mul
__}
\item
[{\tt __int__(self)}]
\itemjoin
\item
[{\tt __long__(self)}]
\itemjoin
\item
[{\tt __float__(self)}]
\itembreak
Called to implement the built-in functions
\verb
@
int()
@
,
\verb
@
long()
@
and
\verb
@
float()
@
. Should return a value of the appropriate type.
\ttindex
{__
float
__}
\ttindex
{__
long
__}
\ttindex
{__
int
__}
\item
[{\tt __oct__(self)}]
\itemjoin
\item
[{\tt __hex__(self)}]
\itembreak
Called to implement the built-in functions
\verb
@
oct()
@
and
\verb
@
hex()
@
. Should return a string value.
\ttindex
{__
hex
__}
\ttindex
{__
oct
__}
\end{description}
Doc/ref/ref4.tex
View file @
d2a59a22
...
...
@@ -77,6 +77,11 @@ construct {\tt from \ldots import *}, the semantics of names not
explicitly mentioned in a
{
\tt
global
}
statement change subtly: name
lookup first searches the local name space, then the global one, then
the built-in one.
}
\bimodindex
{__
builtin
__}
\stindex
{
from
}
\stindex
{
exec
}
\stindex
{
global
}
\ttindex
{
NameError
}
The following table lists the meaning of the local and global name
space for various types of code blocks. The name space for a
...
...
@@ -107,6 +112,7 @@ Expression read by \verb@input@
\hline
\end{tabular}
\end{center}
\bimodindex
{__
main
__}
Notes:
...
...
Doc/ref/ref8.tex
View file @
d2a59a22
...
...
@@ -31,6 +31,7 @@ one statement (possibly compound) at a time. The initial environment
is identical to that of a complete program; each statement is executed
in the name space of
\verb
@
__main__
@
.
\index
{
interactive mode
}
\bimodindex
{__
main
__}
Under
{
\UNIX
}
, a complete program can be passed to the interpreter in
three forms: with the
{
\bf
-c
}
{
\it
string
}
command line option, as a
...
...
Doc/ref3.tex
View file @
d2a59a22
...
...
@@ -585,6 +585,7 @@ method named \verb@__getitem__@, and \verb@x@ is an instance of this
class, then
\verb
@
x[i]
@
is equivalent to
\verb
@
x.__getitem__(i)
@
.
(The reverse is not true --- if
\verb
@
x
@
is a list object,
\verb
@
x.__getitem__(i)
@
is not equivalent to
\verb
@
x[i]
@
.)
\ttindex
{__
getitem
__}
Except for
\verb
@
__repr__
@
,
\verb
@
__str__
@
and
\verb
@
__cmp__
@
,
attempts to execute an
...
...
@@ -594,6 +595,9 @@ object's class and address.
For
\verb
@
__cmp__
@
, the default is to compare instances based on their
address.
For
\verb
@
__str__
@
, the default is to use
\verb
@
__repr__
@
.
\ttindex
{__
repr
__}
\ttindex
{__
str
__}
\ttindex
{__
cmp
__}
\subsection
{
Special methods for any type
}
...
...
@@ -606,6 +610,9 @@ to the class constructor expression. If a base class has an
\code
{__
init
__}
method the derived class's
\code
{__
init
__}
method must
explicitly call it to ensure proper initialization of the base class
part of the instance.
\ttindex
{__
init
__}
\indexii
{
class
}{
constructor
}
\item
[{\tt __del__(self)}]
Called when the instance is about to be destroyed. If a base class
...
...
@@ -617,6 +624,8 @@ reference to it. It may then be called at a later time when this new
reference is deleted. It is not guaranteed that
\code
{__
del
__}
methods are called for objects that still exist when
the interpreter exits.
\ttindex
{__
del
__}
\stindex
{
del
}
Note that
\code
{
del x
}
doesn't directly call
\code
{
x.
__
del
__}
--- the
former decrements the reference count for
\code
{
x
}
by one, but
...
...
@@ -625,6 +634,8 @@ former decrements the reference count for \code{x} by one, but
\item
[{\tt __repr__(self)}]
Called by the
\verb
@
repr()
@
built-in function and by string conversions
(reverse or backward quotes) to compute the string representation of an object.
\ttindex
{__
repr
__}
\bifuncindex
{
repr
}
\indexii
{
string
}{
conversion
}
\indexii
{
reverse
}{
quotes
}
\indexii
{
backward
}{
quotes
}
...
...
@@ -633,6 +644,9 @@ Called by the \verb@repr()@ built-in function and by string conversions
\item
[{\tt __str__(self)}]
Called by the
\verb
@
str()
@
built-in function and by the
\verb
@
print
@
statement compute the string representation of an object.
\ttindex
{__
str
__}
\bifuncindex
{
str
}
\stindex
{
print
}
\item
[{\tt __cmp__(self, other)}]
Called by all comparison operations. Should return -1 if
...
...
@@ -642,6 +656,9 @@ instances are compared by object identity (``address'').
(Implementation note: due to limitations in the interpreter,
exceptions raised by comparisons are ignored, and the objects will be
considered equal in this case.)
\ttindex
{__
cmp
__}
\bifuncindex
{
cmp
}
\index
{
comparisons
}
\item
[{\tt __hash__(self)}]
Called for the key object for dictionary operations,
...
...
@@ -659,9 +676,14 @@ implements a \code{__cmp__} method it should not implement
\code
{__
hash
__}
, since the dictionary implementation assumes that a
key's hash value is a constant.
\obindex
{
dictionary
}
\ttindex
{__
cmp
__}
\ttindex
{__
hash
__}
\bifuncindex
{
hash
}
\item
[{\tt __call__(self, *args)}]
Called when the instance is ``called'' as a function.
\ttindex
{__
call
__}
\indexii
{
call
}{
instance
}
\end{description}
...
...
@@ -677,6 +699,7 @@ access for class instances.
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
the class tree for
\code
{
self
}
).
\code
{
name
}
is the attribute name.
\ttindex
{__
getattr
__}
Note that if the attribute is found through the normal mechanism,
\code
{__
getattr
__}
is not called. (This is an asymmetry between
...
...
@@ -687,22 +710,26 @@ instance.
Note that at least for instance variables,
\code
{__
getattr
__}
can fake
total control by simply not inserting any values in the instance
attribute dictionary.
\ttindex
{__
setattr
__}
\item
[{\tt __setattr__(self, name, value)}]
Called when an attribute assignment is attempted. This is called
instead of the normal mechanism (i.e. store the value as an instance
attribute).
\code
{
name
}
is the attribute name,
\code
{
value
}
is the
value to be assigned to it.
\ttindex
{__
setattr
__}
If
\code
{__
setattr
__}
wants to assign to an instance attribute, it
should not simply execute
\code
{
self.
\var
{
name
}
= value
}
--- this would
cause a recursive call. Instead, it should insert the value in the
dictionary of instance attributes, e.g.
\code
{
self.
__
dict
__
[name] =
value
}
.
\ttindex
{__
dict
__}
\item
[{\tt __delattr__(self, name)}]
Like
\code
{__
setattr
__}
but for attribute deletion instead of
assignment.
\ttindex
{__
delattr
__}
\end{description}
...
...
@@ -716,19 +743,23 @@ Called to implement the built-in function \verb@len()@. Should return
the length of the object, an integer
\verb
@
>=
@
0. Also, an object
whose
\verb
@
__len__()
@
method returns 0 is considered to be false in a
Boolean context.
\ttindex
{__
len
__}
\item
[{\tt __getitem__(self, key)}]
Called to implement evaluation of
\verb
@
self[key]
@
. Note that the
special interpretation of negative keys (if the class wishes to
emulate a sequence type) is up to the
\verb
@
__getitem__
@
method.
\ttindex
{__
getitem
__}
\item
[{\tt __setitem__(self, key, value)}]
Called to implement assignment to
\verb
@
self[key]
@
. Same note as for
\verb
@
__getitem__
@
.
\ttindex
{__
setitem
__}
\item
[{\tt __delitem__(self, key)}]
Called to implement deletion of
\verb
@
self[key]
@
. Same note as for
\verb
@
__getitem__
@
.
\ttindex
{__
delitem
__}
\end{description}
...
...
@@ -743,14 +774,17 @@ Called to implement evaluation of \verb@self[i:j]@. Note that missing
respectively, and
\verb
@
len(self)
@
has been added (once) to originally
negative
\verb
@
i
@
or
\verb
@
j
@
by the time this function is called
(unlike for
\verb
@
__getitem__
@
).
\ttindex
{__
getslice
__}
\item
[{\tt __setslice__(self, i, j, sequence)}]
Called to implement assignment to
\verb
@
self[i:j]
@
. Same notes as for
\verb
@
__getslice__
@
.
\ttindex
{__
setslice
__}
\item
[{\tt __delslice__(self, i, j)}]
Called to implement deletion of
\verb
@
self[i:j]
@
. Same notes as for
\verb
@
__getslice__
@
.
\ttindex
{__
delslice
__}
\end{description}
...
...
@@ -774,6 +808,18 @@ Called to implement deletion of \verb@self[i:j]@. Same notes as for
Called to implement the binary arithmetic operations (
\verb
@
+
@
,
\verb
@
-
@
,
\verb
@
*
@
,
\verb
@
/
@
,
\verb
@
%
@
,
\verb
@
divmod()
@
,
\verb
@
pow()
@
,
\verb
@
<<
@
,
\verb
@
>>
@
,
\verb
@
&
@
,
\verb
@
^
@
,
\verb
@
|
@
).
\ttindex
{__
or
__}
\ttindex
{__
xor
__}
\ttindex
{__
and
__}
\ttindex
{__
rshift
__}
\ttindex
{__
lshift
__}
\ttindex
{__
pow
__}
\ttindex
{__
divmod
__}
\ttindex
{__
mod
__}
\ttindex
{__
div
__}
\ttindex
{__
mul
__}
\ttindex
{__
sub
__}
\ttindex
{__
add
__}
\item
[{\tt __neg__(self)}]
\itemjoin
\item
[{\tt __pos__(self)}]
\itemjoin
...
...
@@ -781,10 +827,15 @@ Called to implement the binary arithmetic operations (\verb@+@,
\item
[{\tt __invert__(self)}]
\itembreak
Called to implement the unary arithmetic operations (
\verb
@
-
@
,
\verb
@
+
@
,
\verb
@
abs()
@
and
\verb
@
~
@
).
\ttindex
{__
invert
__}
\ttindex
{__
abs
__}
\ttindex
{__
pos
__}
\ttindex
{__
neg
__}
\item
[{\tt __nonzero__(self)}]
Called to implement boolean testing; should return 0 or 1. An
alternative name for this method is
\verb
@
__len__
@
.
\ttindex
{__
nonzero
__}
\item
[{\tt __coerce__(self, other)}]
Called to implement ``mixed-mode'' numeric arithmetic. Should either
...
...
@@ -794,6 +845,7 @@ would be the type of other, it is sufficient to return None, since the
interpreter will also ask the other 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 here).
\ttindex
{__
coerce
__}
Note that this method is not called to coerce the arguments to
\verb
@
+
@
and
\verb
@
*
@
, because these are also used to implement sequence
...
...
@@ -803,16 +855,22 @@ same reason, in \verb@n*x@, where \verb@n@ is a built-in number and
\footnote
{
The interpreter should really distinguish between
user-defined classes implementing sequences, mappings or numbers, but
currently it doesn't --- hence this strange exception.
}
\ttindex
{__
mul
__}
\item
[{\tt __int__(self)}]
\itemjoin
\item
[{\tt __long__(self)}]
\itemjoin
\item
[{\tt __float__(self)}]
\itembreak
Called to implement the built-in functions
\verb
@
int()
@
,
\verb
@
long()
@
and
\verb
@
float()
@
. Should return a value of the appropriate type.
\ttindex
{__
float
__}
\ttindex
{__
long
__}
\ttindex
{__
int
__}
\item
[{\tt __oct__(self)}]
\itemjoin
\item
[{\tt __hex__(self)}]
\itembreak
Called to implement the built-in functions
\verb
@
oct()
@
and
\verb
@
hex()
@
. Should return a string value.
\ttindex
{__
hex
__}
\ttindex
{__
oct
__}
\end{description}
Doc/ref4.tex
View file @
d2a59a22
...
...
@@ -77,6 +77,11 @@ construct {\tt from \ldots import *}, the semantics of names not
explicitly mentioned in a
{
\tt
global
}
statement change subtly: name
lookup first searches the local name space, then the global one, then
the built-in one.
}
\bimodindex
{__
builtin
__}
\stindex
{
from
}
\stindex
{
exec
}
\stindex
{
global
}
\ttindex
{
NameError
}
The following table lists the meaning of the local and global name
space for various types of code blocks. The name space for a
...
...
@@ -107,6 +112,7 @@ Expression read by \verb@input@
\hline
\end{tabular}
\end{center}
\bimodindex
{__
main
__}
Notes:
...
...
Doc/ref8.tex
View file @
d2a59a22
...
...
@@ -31,6 +31,7 @@ one statement (possibly compound) at a time. The initial environment
is identical to that of a complete program; each statement is executed
in the name space of
\verb
@
__main__
@
.
\index
{
interactive mode
}
\bimodindex
{__
main
__}
Under
{
\UNIX
}
, a complete program can be passed to the interpreter in
three forms: with the
{
\bf
-c
}
{
\it
string
}
command line option, as a
...
...
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