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
293dd4b7
Commit
293dd4b7
authored
Jun 04, 2002
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix up Guido's markup.
parent
16c8d702
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
Doc/ref/ref3.tex
Doc/ref/ref3.tex
+24
-24
No files found.
Doc/ref/ref3.tex
View file @
293dd4b7
...
...
@@ -12,7 +12,7 @@ program is represented by objects or by relations between objects.
Every object has an identity, a type and a value. An object's
\emph
{
identity
}
never changes once it has been created; you may think
of it as the object's address in memory. The `
\
code
{
is
}
' operator
of it as the object's address in memory. The `
\
keyword
{
is
}
' operator
compares the identity of two objects; the
\function
{
id()
}
\bifuncindex
{
id
}
function returns an integer
representing its identity (currently implemented as its address).
...
...
@@ -1540,10 +1540,10 @@ original arguments to the operation.
\item
New-style classes (those derived from
\c
ode
{
object
}
) never invoke the
\
code
{__
coerce
__
}
method in response to a binary operator; the only
time
\
code
{__
coerce
__
}
is invoked is when the built-in function
\
code
{
coerce()
}
is called.
New-style classes (those derived from
\c
lass
{
object
}
) never invoke the
\
method
{__
coerce
__
()
}
method in response to a binary operator; the only
time
\
method
{__
coerce
__
()
}
is invoked is when the built-in function
\
function
{
coerce()
}
is called.
\item
...
...
@@ -1565,7 +1565,7 @@ binary operator, and \method{__iadd__} for the in-place variant.
For objects
\var
{
x
}
and
\var
{
y
}
, first
\code
{
\var
{
x
}
.
__
op
__
(
\var
{
y
}
)
}
is tried. If this is not implemented or returns
\code
{
NotImplemented
}
,
\code
{
\var
{
y
}
.
__
rop
__
(
\var
{
x
}
)
}
is tried. If this is also not
implemented or returns
\code
{
NotImplemented
}
, a
\
code
{
TypeError
}
implemented or returns
\code
{
NotImplemented
}
, a
\
exception
{
TypeError
}
exception is raised. But see the following exception:
\item
...
...
@@ -1573,8 +1573,8 @@ exception is raised. But see the following exception:
Exception to the previous item: if the left operand is an instance of
a built-in type or a new-style class, and the right operand is an
instance of a proper subclass of that type or class, the right
operand's
\
code
{__
rop
__
}
method is tried
\emph
{
before
}
the left
operand's
\
code
{__
op
__
}
method. This is done so that a subclass can
operand's
\
method
{__
rop
__
()
}
method is tried
\emph
{
before
}
the left
operand's
\
method
{__
op
__
()
}
method. This is done so that a subclass can
completely override binary operators. Otherwise, the left operand's
__
op
__
method would always accept the right operand: when an instance
of a given class is expected, an instance of a subclass of that class
...
...
@@ -1583,17 +1583,17 @@ is always acceptable.
\item
When either operand type defines a coercion, this coercion is called
before that type's
\
code
{__
op
__}
or
\code
{__
rop
__}
method is called,
but no sooner. If the coercion returns an object of a different type
for the operand whose coercion is invoked, part of the process is
redone using the new object.
before that type's
\
method
{__
op
__
()
}
or
\method
{__
rop
__
()
}
method is
called, but no sooner. If the coercion returns an object of a
different type for the operand whose coercion is invoked, part of the
process is
redone using the new object.
\item
When an in-place operator (like `
\code
{
+=
}
') is used, if the left
operand implements
\
code
{__
iop
__}
, it is invoked without any coercion.
When the operation falls back to
\code
{__
op
__}
and/or
\code
{__
rop
__}
,
the normal coercion rules apply.
operand implements
\
method
{__
iop
__
()
}
, it is invoked without any
coercion. When the operation falls back to
\method
{__
op
__
()
}
and/or
\method
{__
rop
__
()
}
,
the normal coercion rules apply.
\item
...
...
@@ -1604,23 +1604,23 @@ sequence concatenation, sequence concatenation is invoked.
In
\var
{
x
}
\code
{
*
}
\var
{
y
}
, if one operator is a sequence that
implements sequence repetition, and the other is an integer
(
\c
ode
{
int
}
or
\code
{
long
}
), sequence repetition is invoked.
(
\c
lass
{
int
}
or
\class
{
long
}
), sequence repetition is invoked.
\item
Rich comparisons (implemented by methods
\
code
{__
eq
__
}
and so on)
Rich comparisons (implemented by methods
\
method
{__
eq
__
()
}
and so on)
never use coercion. Three-way comparison (implemented by
\
code
{__
cmp
__
}
) does use coercion under the same conditions as
\
method
{__
cmp
__
()
}
) does use coercion under the same conditions as
other binary operations use it.
\item
In the current implementation, the built-in numeric types
\c
ode
{
int
}
,
\c
ode
{
long
}
and
\code
{
float
}
do not use coercion; the type
\c
ode
{
complex
}
however does use it. The difference can become
In the current implementation, the built-in numeric types
\c
lass
{
int
}
,
\c
lass
{
long
}
and
\class
{
float
}
do not use coercion; the type
\c
lass
{
complex
}
however does use it. The difference can become
apparent when subclassing these types. Over time, the type
\c
ode
{
complex
}
may be fixed to avoid coercion. All these types
implement a
\
code
{__
coerce
__
}
method, for use by the built-in
\
code
{
coerce
}
function.
\c
lass
{
complex
}
may be fixed to avoid coercion. All these types
implement a
\
method
{__
coerce
__
()
}
method, for use by the built-in
\
function
{
coerce()
}
function.
\end{itemize}
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