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
c312f6e2
Commit
c312f6e2
authored
Apr 13, 2001
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work around the conversion of ">>" and "<<" to guillemets. Reported by Ping.
Wrap some long lines and fix some markup nits.
parent
e890ef5e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
51 deletions
+56
-51
Doc/ref/ref3.tex
Doc/ref/ref3.tex
+56
-51
No files found.
Doc/ref/ref3.tex
View file @
c312f6e2
...
...
@@ -1233,22 +1233,24 @@ object is created instead, and passed to \method{__getitem__()} instead.
Called to implement assignment to
\code
{
\var
{
self
}
[
\var
{
i
}
:
\var
{
j
}
]
}
.
Same notes for
\var
{
i
}
and
\var
{
j
}
as for
\method
{__
getslice
__
()
}
.
This method is deprecated. If no
\method
{__
setslice
__
()
}
is found, a slice
object is created instead, and passed to
\method
{__
setitem
__
()
}
instead.
This method is deprecated. If no
\method
{__
setslice
__
()
}
is found, a
slice object is created instead, and passed to
\method
{__
setitem
__
()
}
instead.
\end{methoddesc}
\begin{methoddesc}
[sequence object]
{__
delslice
__}{
self, i, 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
__
()
}
.
This method is deprecated. If no
\method
{__
delslice
__
()
}
is found, a slice
object is created instead, and passed to
\method
{__
delitem
__
()
}
instead.
This method is deprecated. If no
\method
{__
delslice
__
()
}
is found, a
slice object is created instead, and passed to
\method
{__
delitem
__
()
}
instead.
\end{methoddesc}
Notice that these methods are only invoked when a single slice with a
single
colon is used, and the slice method is available. For slice operations
involving extended slice notation, or in absence of the slice methods,
\method
{__
getitem
__
()
}
,
\method
{__
setitem
__
()
}
or
\method
{__
delitem
__
()
}
is
called with a slice object as argument.
Notice that these methods are only invoked when a single slice with a
single colon is used, and the slice method is available. For slice
operations involving extended slice notation, or in absence of the
slice methods,
\method
{__
getitem
__
()
}
,
\method
{__
setitem
__
()
}
or
\method
{__
delitem
__
()
}
is
called with a slice object as argument.
The following example demonstrate how to make your program or module
compatible with earlier versions of Python (assuming that methods
...
...
@@ -1326,10 +1328,10 @@ These functions are
called to implement the binary arithmetic operations (
\code
{
+
}
,
\code
{
-
}
,
\code
{
*
}
,
\code
{
/
}
,
\code
{
\%
}
,
\function
{
divmod()
}
\bifuncindex
{
divmod
}
,
\function
{
pow()
}
\bifuncindex
{
pow
}
,
\code
{
**
}
,
\code
{
<
<
}
,
\code
{
>>
}
,
\code
{
\&
}
,
\code
{
\^
}
,
\code
{
|
}
). For instance, to evaluate the
e
xpression
\var
{
x
}
\code
{
+
}
\var
{
y
}
, where
\var
{
x
}
is an instance of a
class that has an
\method
{__
add
__
()
}
method,
\function
{
pow()
}
\bifuncindex
{
pow
}
,
\code
{
**
}
,
\code
{
<
}
\code
{
<
}
,
\code
{
>
}
\code
{
>
}
,
\code
{
\&
}
,
\code
{
\^
}
,
\code
{
|
}
). For instance, to
e
valuate the expression
\var
{
x
}
\code
{
+
}
\var
{
y
}
, where
\var
{
x
}
is an
instance of a
class that has an
\method
{__
add
__
()
}
method,
\code
{
\var
{
x
}
.
__
add
__
(
\var
{
y
}
)
}
is called. Note that
\method
{__
pow
__
()
}
should be defined to accept an optional third
argument if the ternary version of the built-in
...
...
@@ -1352,14 +1354,15 @@ These functions are
called to implement the binary arithmetic operations (
\code
{
+
}
,
\code
{
-
}
,
\code
{
*
}
,
\code
{
/
}
,
\code
{
\%
}
,
\function
{
divmod()
}
\bifuncindex
{
divmod
}
,
\function
{
pow()
}
\bifuncindex
{
pow
}
,
\code
{
**
}
,
\code
{
<<
}
,
\code
{
>>
}
,
\code
{
\&
}
,
\code
{
\^
}
,
\code
{
|
}
) with reflected (swapped) operands. These
functions are only called if the left operand does not support the
corresponding operation. For instance, to evaluate the expression
\var
{
x
}
\code
{
-
}
\var
{
y
}
, where
\var
{
y
}
is an instance of a class that
has an
\method
{__
rsub
__
()
}
method,
\code
{
\var
{
y
}
.
__
rsub
__
(
\var
{
x
}
)
}
is
called. Note that ternary
\function
{
pow()
}
\bifuncindex
{
pow
}
will not
try calling
\method
{__
rpow
__
()
}
(the coercion rules would become too
\function
{
pow()
}
\bifuncindex
{
pow
}
,
\code
{
**
}
,
\code
{
<
}
\code
{
<
}
,
\code
{
>
}
\code
{
>
}
,
\code
{
\&
}
,
\code
{
\^
}
,
\code
{
|
}
) with reflected
(swapped) operands. These functions are only called if the left
operand does not support the corresponding operation. For instance,
to evaluate the expression
\var
{
x
}
\code
{
-
}
\var
{
y
}
, where
\var
{
y
}
is an
instance of a class that has an
\method
{__
rsub
__
()
}
method,
\code
{
\var
{
y
}
.
__
rsub
__
(
\var
{
x
}
)
}
is called. Note that ternary
\function
{
pow()
}
\bifuncindex
{
pow
}
will not try calling
\method
{__
rpow
__
()
}
(the coercion rules would become too
complicated).
\end{methoddesc}
...
...
@@ -1374,27 +1377,28 @@ complicated).
\methodline
[numeric object]
{__
iand
__}{
self, other
}
\methodline
[numeric object]
{__
ixor
__}{
self, other
}
\methodline
[numeric object]
{__
ior
__}{
self, other
}
These methods are called to implement the augmented arithmetic operations
(
\code
{
+=
}
,
\code
{
-=
}
,
\code
{
*=
}
,
\code
{
/=
}
,
\code
{
\%
=
}
,
\code
{
**=
}
,
\code
{
<<=
}
,
\code
{
>>=
}
,
\code
{
\&
=
}
,
\code
{
\^
=
}
,
\code
{
|=
}
). These methods
should attempt to do the operation in-place (modifying
\var
{
self
}
) and
return the result (which could be, but does not have to be,
\var
{
self
}
). If
a specific method is not defined, the augmented operation falls back to the
normal methods. For instance, to evaluate the expression
\var
{
x
}
\code
{
+=
}
\var
{
y
}
, where
\var
{
x
}
is an instance of a class that has an
\method
{__
iadd
__
()
}
method,
\code
{
\var
{
x
}
.
__
iadd
__
(
\var
{
y
}
)
}
is called. If
\var
{
x
}
is an instance of a class that does not define a
\method
{__
iadd()
}
method,
\code
{
\var
{
x
}
.
__
add
__
(
\var
{
y
}
)
}
and
\code
{
\var
{
y
}
.
__
radd
__
(
\var
{
x
}
)
}
are considered, as with the evaluation of
\var
{
x
}
\code
{
+
}
\var
{
y
}
.
These methods are called to implement the augmented arithmetic
operations (
\code
{
+=
}
,
\code
{
-=
}
,
\code
{
*=
}
,
\code
{
/=
}
,
\code
{
\%
=
}
,
\code
{
**=
}
,
\code
{
<
}
\code
{
<=
}
,
\code
{
>
}
\code
{
>=
}
,
\code
{
\&
=
}
,
\code
{
\^
=
}
,
\code
{
|=
}
). These methods should attempt to do the
operation in-place (modifying
\var
{
self
}
) and return the result (which
could be, but does not have to be,
\var
{
self
}
). If a specific method
is not defined, the augmented operation falls back to the normal
methods. For instance, to evaluate the expression
\var
{
x
}
\code
{
+=
}
\var
{
y
}
, where
\var
{
x
}
is an instance of a class that
has an
\method
{__
iadd
__
()
}
method,
\code
{
\var
{
x
}
.
__
iadd
__
(
\var
{
y
}
)
}
is
called. If
\var
{
x
}
is an instance of a class that does not define a
\method
{__
iadd()
}
method,
\code
{
\var
{
x
}
.
__
add
__
(
\var
{
y
}
)
}
and
\code
{
\var
{
y
}
.
__
radd
__
(
\var
{
x
}
)
}
are considered, as with the
evaluation of
\var
{
x
}
\code
{
+
}
\var
{
y
}
.
\end{methoddesc}
\begin{methoddesc}
[numeric object]
{__
neg
__}{
self
}
\methodline
[numeric object]
{__
pos
__}{
self
}
\methodline
[numeric object]
{__
abs
__}{
self
}
\methodline
[numeric object]
{__
invert
__}{
self
}
Called to implement the unary arithmetic operations (
\code
{
-
}
,
\code
{
+
}
,
\function
{
abs()
}
\bifuncindex
{
abs
}
and
\code
{
\~
{}}
).
Called to implement the unary arithmetic operations (
\code
{
-
}
,
\
code
{
+
}
,
\
function
{
abs()
}
\bifuncindex
{
abs
}
and
\code
{
\~
{}}
).
\end{methoddesc}
\begin{methoddesc}
[numeric object]
{__
complex
__}{
self
}
...
...
@@ -1427,17 +1431,17 @@ the other type here).
\end{methoddesc}
\strong
{
Coercion rules
}
: to evaluate
\var
{
x
}
\var
{
op
}
\var
{
y
}
, the
following steps are taken (where
\method
{__
op
__
()
}
and
\method
{__
r
op
__
()
}
are the method names corresponding to
\var
{
op
}
,
e.g., if
var
{
op
}
is `
\code
{
+
}
',
\method
{__
add
__
()
}
and
following steps are taken (where
\method
{__
\var
{
op
}
__
()
}
and
\method
{__
r
\var
{
op
}__
()
}
are the method names corresponding to
\var
{
op
}
, e.g., if
\
var
{
op
}
is `
\code
{
+
}
',
\method
{__
add
__
()
}
and
\method
{__
radd
__
()
}
are used). If an exception occurs at any point,
the evaluation is abandoned and exception handling takes over.
\begin{itemize}
\item
[0.]
If
\var
{
x
}
is a string object and
op is the modulo operator (
\%
),
the string formatting operation is invoked and the remaining steps are
skipped.
\item
[0.]
If
\var
{
x
}
is a string object and
\var
{
op
}
is the modulo
operator (
\%
), the string formatting operation is invoked and
the remaining steps are
skipped.
\item
[1.]
If
\var
{
x
}
is a class instance:
...
...
@@ -1451,8 +1455,8 @@ skipped.
\item
[1b.]
If neither
\var
{
x
}
nor
\var
{
y
}
is a class instance
after coercion, go to step 3.
\item
[1c.]
If
\var
{
x
}
has a method
\method
{__
op
__
()
}
, return
\code
{
\var
{
x
}
.
__
op
__
(
\var
{
y
}
)
}
; otherwise, restore
\var
{
x
}
and
\item
[1c.]
If
\var
{
x
}
has a method
\method
{__
\var
{
op
}
__
()
}
, return
\code
{
\var
{
x
}
.
__
\var
{
op
}
__
(
\var
{
y
}
)
}
; otherwise, restore
\var
{
x
}
and
\var
{
y
}
to their value before step 1a.
\end{itemize}
...
...
@@ -1469,9 +1473,9 @@ skipped.
\item
[2b.]
If neither
\var
{
x
}
nor
\var
{
y
}
is a class instance
after coercion, go to step 3.
\item
[2b.]
If
\var
{
y
}
has a method
\method
{__
r
op
__
()
}
, return
\code
{
\var
{
y
}
.
__
rop
__
(
\var
{
x
}
)
}
; otherwise, restore
\var
{
x
}
and
\var
{
y
}
to their value before step 2a.
\item
[2b.]
If
\var
{
y
}
has a method
\method
{__
r
\var
{
op
}__
()
}
,
return
\code
{
\var
{
y
}
.
__
r
\var
{
op
}__
(
\var
{
x
}
)
}
; otherwise,
restore
\var
{
x
}
and
\var
{
y
}
to their value before step 2a.
\end{itemize}
...
...
@@ -1480,11 +1484,12 @@ instance.
\begin{itemize}
\item
[3a.]
If
op is `
\code
{
+
}
' and
\var
{
x
}
is a sequence,
sequence concatenation is invoked.
\item
[3a.]
If
\var
{
op
}
is `
\code
{
+
}
' and
\var
{
x
}
is a
sequence
, sequence
concatenation is invoked.
\item
[3b.]
If op is `
\code
{
*
}
' and one operand is a sequence
and the other an integer, sequence repetition is invoked.
\item
[3b.]
If
\var
{
op
}
is `
\code
{
*
}
' and one operand is a
sequence and the other an integer, sequence repetition is
invoked.
\item
[3c.]
Otherwise, both operands must be numbers; they are
coerced to a common type if possible, and the numeric
...
...
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