Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2c6556

Browse files
committed
Lots of small changes collected over months...
1 parent 6ac258d commit b2c6556

7 files changed

Lines changed: 157 additions & 163 deletions

File tree

Doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ qua:
3131
bibtex qua
3232
latex qua
3333
latex qua
34-
dvips lib >qua.ps
34+
dvips qua >qua.ps
3535

3636
libinfo:
3737
@echo This may take a while...

Doc/ref/ref3.tex

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,17 @@ \section{The standard type hierarchy} \label{types}
290290
\begin{description}
291291

292292
\item[Dictionaries]
293-
These represent finite sets of objects indexed by strings.
293+
These represent finite sets of objects indexed by almost arbitrary
294+
values. The only types of values not acceptable as keys are values
295+
containing lists or dictionaries or other mutable types that are
296+
compared by value rather than by object identity --- the reason being
297+
that the implementation requires that a key's hash value be constant.
298+
Numeric types used for keys obey the normal rules for numeric
299+
comparison: if two numbers compare equal (e.g. 1 and 1.0) then they
300+
can be used interchangeably to index the same dictionary entry.
301+
294302
Dictionaries are mutable; they are created by the \verb\{...}\
295-
notation (see section \ref{dict}). (Implementation note: the strings
296-
used for indexing must not contain null bytes.)
303+
notation (see section \ref{dict}).
297304
\obindex{dictionary}
298305
\obindex{mutable}
299306

@@ -409,7 +416,7 @@ \section{The standard type hierarchy} \label{types}
409416
\obindex{instance}
410417
\indexii{class object}{call}
411418
\index{container}
412-
\index{dictionary}
419+
\obindex{dictionary}
413420
\indexii{class}{attribute}
414421

415422
Class attribute assignments update the class's dictionary, never the
@@ -589,12 +596,30 @@ \subsection{Special methods for any type}
589596
Called by the \verb\print\ statement and conversions (reverse quotes) to
590597
compute the string representation of an object.
591598

592-
\item[\tt _cmp__(self, other)]
599+
\item[\tt __cmp__(self, other)]
593600
Called by all comparison operations. Should return -1 if
594601
\verb\self < other\, 0 if \verb\self == other\, +1 if
595-
\verb\self > other\. (Implementation note: due to limitations in the
596-
interpreter, exceptions raised by comparisons are ignored, and the
597-
objects will be considered equal in this case.)
602+
\verb\self > other\. If no \code{__cmp__} operation is defined, class
603+
instances are compared by object identity (``address'').
604+
(Implementation note: due to limitations in the interpreter,
605+
exceptions raised by comparisons are ignored, and the objects will be
606+
considered equal in this case.)
607+
608+
\item[\tt __hash__(self)]
609+
Called by dictionary operations and by the built-in function
610+
\code{hash()}. Should return a 32-bit integer usable as a hash value
611+
for dictionary operations. The only required property is that objects
612+
which compare equal have the same hash value; it is advised to somehow
613+
mix together (e.g. using exclusing or) the hash values for the
614+
components of the object that also play a part in comparison of
615+
objects. If a class does not define a \code{__cmp__} method it should
616+
not define a \code{__hash__} operation either; if it defines
617+
\code{__cmp__} but not \code{__hash__} its instances will not be
618+
usable as dictionary keys. If a class defines mutable objects and
619+
implements a \code{__cmp__} method it should not implement
620+
\code{__hash__}, since the dictionary implementation assumes that a
621+
key's hash value is a constant.
622+
\obindex{dictionary}
598623

599624
\end{description}
600625

Doc/ref/ref5.tex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ \subsection{Dictionary displays} \label{dict}
176176
entries of the dictionary: each key object is used as a key into the
177177
dictionary to store the corresponding datum.
178178

179-
Keys must be strings, otherwise a \verb\TypeError\ exception is
180-
raised. Clashes between duplicate keys are not detected; the last
179+
Restrictions on the types of the key values are listed earlier in
180+
section \ref{types}.
181+
Clashes between duplicate keys are not detected; the last
181182
datum (textually rightmost in the display) stored for a given key
182183
value prevails.
183184
\exindex{TypeError}
@@ -565,10 +566,10 @@ \section{Comparisons}
565566
Mappings (dictionaries) are compared through lexicographic
566567
comparison of their sorted (key, value) lists.%
567568
\footnote{This is expensive since it requires sorting the keys first,
568-
but about the only sensible definition. It was tried to compare
569-
dictionaries by identity only, but this caused surprises because
570-
people expected to be able to test a dictionary for emptiness by
571-
comparing it to {\tt \{\}}.}
569+
but about the only sensible definition. An earlier version of Python
570+
compared dictionaries by identity only, but this caused surprises
571+
because people expected to be able to test a dictionary for emptiness
572+
by comparing it to {\tt \{\}}.}
572573

573574
\item
574575
Most other types compare unequal unless they are the same object;

Doc/ref3.tex

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,17 @@ \section{The standard type hierarchy} \label{types}
290290
\begin{description}
291291

292292
\item[Dictionaries]
293-
These represent finite sets of objects indexed by strings.
293+
These represent finite sets of objects indexed by almost arbitrary
294+
values. The only types of values not acceptable as keys are values
295+
containing lists or dictionaries or other mutable types that are
296+
compared by value rather than by object identity --- the reason being
297+
that the implementation requires that a key's hash value be constant.
298+
Numeric types used for keys obey the normal rules for numeric
299+
comparison: if two numbers compare equal (e.g. 1 and 1.0) then they
300+
can be used interchangeably to index the same dictionary entry.
301+
294302
Dictionaries are mutable; they are created by the \verb\{...}\
295-
notation (see section \ref{dict}). (Implementation note: the strings
296-
used for indexing must not contain null bytes.)
303+
notation (see section \ref{dict}).
297304
\obindex{dictionary}
298305
\obindex{mutable}
299306

@@ -409,7 +416,7 @@ \section{The standard type hierarchy} \label{types}
409416
\obindex{instance}
410417
\indexii{class object}{call}
411418
\index{container}
412-
\index{dictionary}
419+
\obindex{dictionary}
413420
\indexii{class}{attribute}
414421

415422
Class attribute assignments update the class's dictionary, never the
@@ -589,12 +596,30 @@ \subsection{Special methods for any type}
589596
Called by the \verb\print\ statement and conversions (reverse quotes) to
590597
compute the string representation of an object.
591598

592-
\item[\tt _cmp__(self, other)]
599+
\item[\tt __cmp__(self, other)]
593600
Called by all comparison operations. Should return -1 if
594601
\verb\self < other\, 0 if \verb\self == other\, +1 if
595-
\verb\self > other\. (Implementation note: due to limitations in the
596-
interpreter, exceptions raised by comparisons are ignored, and the
597-
objects will be considered equal in this case.)
602+
\verb\self > other\. If no \code{__cmp__} operation is defined, class
603+
instances are compared by object identity (``address'').
604+
(Implementation note: due to limitations in the interpreter,
605+
exceptions raised by comparisons are ignored, and the objects will be
606+
considered equal in this case.)
607+
608+
\item[\tt __hash__(self)]
609+
Called by dictionary operations and by the built-in function
610+
\code{hash()}. Should return a 32-bit integer usable as a hash value
611+
for dictionary operations. The only required property is that objects
612+
which compare equal have the same hash value; it is advised to somehow
613+
mix together (e.g. using exclusing or) the hash values for the
614+
components of the object that also play a part in comparison of
615+
objects. If a class does not define a \code{__cmp__} method it should
616+
not define a \code{__hash__} operation either; if it defines
617+
\code{__cmp__} but not \code{__hash__} its instances will not be
618+
usable as dictionary keys. If a class defines mutable objects and
619+
implements a \code{__cmp__} method it should not implement
620+
\code{__hash__}, since the dictionary implementation assumes that a
621+
key's hash value is a constant.
622+
\obindex{dictionary}
598623

599624
\end{description}
600625

Doc/ref5.tex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ \subsection{Dictionary displays} \label{dict}
176176
entries of the dictionary: each key object is used as a key into the
177177
dictionary to store the corresponding datum.
178178

179-
Keys must be strings, otherwise a \verb\TypeError\ exception is
180-
raised. Clashes between duplicate keys are not detected; the last
179+
Restrictions on the types of the key values are listed earlier in
180+
section \ref{types}.
181+
Clashes between duplicate keys are not detected; the last
181182
datum (textually rightmost in the display) stored for a given key
182183
value prevails.
183184
\exindex{TypeError}
@@ -565,10 +566,10 @@ \section{Comparisons}
565566
Mappings (dictionaries) are compared through lexicographic
566567
comparison of their sorted (key, value) lists.%
567568
\footnote{This is expensive since it requires sorting the keys first,
568-
but about the only sensible definition. It was tried to compare
569-
dictionaries by identity only, but this caused surprises because
570-
people expected to be able to test a dictionary for emptiness by
571-
comparing it to {\tt \{\}}.}
569+
but about the only sensible definition. An earlier version of Python
570+
compared dictionaries by identity only, but this caused surprises
571+
because people expected to be able to test a dictionary for emptiness
572+
by comparing it to {\tt \{\}}.}
572573

573574
\item
574575
Most other types compare unequal unless they are the same object;

0 commit comments

Comments
 (0)