mirror of
https://github.com/python/cpython
synced 2024-09-18 20:11:41 +00:00
Merged revisions 58742-58816 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r58745 | georg.brandl | 2007-11-01 10:19:33 -0700 (Thu, 01 Nov 2007) | 2 lines #1364: os.lstat is available on Windows too, as an alias to os.stat. ........ r58750 | christian.heimes | 2007-11-01 12:48:10 -0700 (Thu, 01 Nov 2007) | 1 line Backport of import tests for bug http://bugs.python.org/issue1293 and bug http://bugs.python.org/issue1342 ........ r58751 | christian.heimes | 2007-11-01 13:11:06 -0700 (Thu, 01 Nov 2007) | 1 line Removed non ASCII text from test as requested by Guido. Sorry :/ ........ r58753 | georg.brandl | 2007-11-01 13:37:02 -0700 (Thu, 01 Nov 2007) | 2 lines Fix markup glitch. ........ r58757 | gregory.p.smith | 2007-11-01 14:08:14 -0700 (Thu, 01 Nov 2007) | 4 lines Fix bug introduced in revision 58385. Database keys could no longer have NULL bytes in them. Replace the errant strdup with a malloc+memcpy. Adds a unit test for the correct behavior. ........ r58758 | gregory.p.smith | 2007-11-01 14:15:36 -0700 (Thu, 01 Nov 2007) | 3 lines Undo revision 58533 58534 fixes. Those were a workaround for a problem introduced by 58385. ........ r58759 | gregory.p.smith | 2007-11-01 14:17:47 -0700 (Thu, 01 Nov 2007) | 2 lines false "fix" undone as correct problem was found and fixed. ........ r58765 | mark.summerfield | 2007-11-02 01:24:59 -0700 (Fri, 02 Nov 2007) | 3 lines Added more file-handling related cross-references. ........ r58766 | nick.coghlan | 2007-11-02 03:09:12 -0700 (Fri, 02 Nov 2007) | 1 line Fix for bug 1705170 - contextmanager swallowing StopIteration (2.5 backport candidate) ........ r58784 | thomas.heller | 2007-11-02 12:10:24 -0700 (Fri, 02 Nov 2007) | 4 lines Issue #1292: On alpha, arm, ppc, and s390 linux systems the --with-system-ffi configure option defaults to "yes" because the bundled libffi sources are too old. ........ r58785 | thomas.heller | 2007-11-02 12:11:23 -0700 (Fri, 02 Nov 2007) | 1 line Enable the full ctypes c_longdouble tests again. ........ r58796 | georg.brandl | 2007-11-02 13:06:17 -0700 (Fri, 02 Nov 2007) | 4 lines Make "hashable" a glossary entry and clarify docs on __cmp__, __eq__ and __hash__. I hope the concept of hashability is better understandable now. Thanks to Tim Hatch for pointing out the flaws here. ........
This commit is contained in:
parent
e845c0f922
commit
2cc30daa86
|
@ -2223,8 +2223,8 @@ Dictionary Objects
|
||||||
.. cfunction:: int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)
|
.. cfunction:: int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)
|
||||||
|
|
||||||
Insert *value* into the dictionary *p* with a key of *key*. *key* must be
|
Insert *value* into the dictionary *p* with a key of *key*. *key* must be
|
||||||
hashable; if it isn't, :exc:`TypeError` will be raised. Return ``0`` on success
|
:term:`hashable`; if it isn't, :exc:`TypeError` will be raised. Return ``0``
|
||||||
or ``-1`` on failure.
|
on success or ``-1`` on failure.
|
||||||
|
|
||||||
|
|
||||||
.. cfunction:: int PyDict_SetItemString(PyObject *p, const char *key, PyObject *val)
|
.. cfunction:: int PyDict_SetItemString(PyObject *p, const char *key, PyObject *val)
|
||||||
|
|
|
@ -141,6 +141,20 @@ Glossary
|
||||||
shared data at a much finer granularity), but performance suffered in the
|
shared data at a much finer granularity), but performance suffered in the
|
||||||
common single-processor case.
|
common single-processor case.
|
||||||
|
|
||||||
|
hashable
|
||||||
|
An object is *hashable* if it has a hash value that never changes during
|
||||||
|
its lifetime (it needs a :meth:`__hash__` method), and can be compared to
|
||||||
|
other objects (it needs an :meth:`__eq__` or :meth:`__cmp__` method).
|
||||||
|
Hashable objects that compare equal must have the same hash value.
|
||||||
|
|
||||||
|
Hashability makes an object usable as a dictionary key and a set member,
|
||||||
|
because these data structures use the hash value internally.
|
||||||
|
|
||||||
|
All of Python's immutable built-in objects are hashable, while all mutable
|
||||||
|
containers (such as lists or dictionaries) are not. Objects that are
|
||||||
|
instances of user-defined classes are hashable by default; they all
|
||||||
|
compare unequal, and their hash value is their :func:`id`.
|
||||||
|
|
||||||
IDLE
|
IDLE
|
||||||
An Integrated Development Environment for Python. IDLE is a basic editor
|
An Integrated Development Environment for Python. IDLE is a basic editor
|
||||||
and interpreter environment that ships with the standard distribution of
|
and interpreter environment that ships with the standard distribution of
|
||||||
|
|
|
@ -260,7 +260,7 @@ compared to an object of a different type, :exc:`TypeError` is raised unless the
|
||||||
comparison is ``==`` or ``!=``. The latter cases return :const:`False` or
|
comparison is ``==`` or ``!=``. The latter cases return :const:`False` or
|
||||||
:const:`True`, respectively.
|
:const:`True`, respectively.
|
||||||
|
|
||||||
:class:`timedelta` objects are hashable (usable as dictionary keys), support
|
:class:`timedelta` objects are :term:`hashable` (usable as dictionary keys), support
|
||||||
efficient pickling, and in Boolean contexts, a :class:`timedelta` object is
|
efficient pickling, and in Boolean contexts, a :class:`timedelta` object is
|
||||||
considered to be true if and only if it isn't equal to ``timedelta(0)``.
|
considered to be true if and only if it isn't equal to ``timedelta(0)``.
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ diffs. For comparing directories and files, see also, the :mod:`filecmp` module.
|
||||||
.. class:: SequenceMatcher
|
.. class:: SequenceMatcher
|
||||||
|
|
||||||
This is a flexible class for comparing pairs of sequences of any type, so long
|
This is a flexible class for comparing pairs of sequences of any type, so long
|
||||||
as the sequence elements are hashable. The basic algorithm predates, and is a
|
as the sequence elements are :term:`hashable`. The basic algorithm predates, and is a
|
||||||
little fancier than, an algorithm published in the late 1980's by Ratcliff and
|
little fancier than, an algorithm published in the late 1980's by Ratcliff and
|
||||||
Obershelp under the hyperbolic name "gestalt pattern matching." The idea is to
|
Obershelp under the hyperbolic name "gestalt pattern matching." The idea is to
|
||||||
find the longest contiguous matching subsequence that contains no "junk"
|
find the longest contiguous matching subsequence that contains no "junk"
|
||||||
|
@ -305,7 +305,7 @@ The :class:`SequenceMatcher` class has this constructor:
|
||||||
on blanks or hard tabs.
|
on blanks or hard tabs.
|
||||||
|
|
||||||
The optional arguments *a* and *b* are sequences to be compared; both default to
|
The optional arguments *a* and *b* are sequences to be compared; both default to
|
||||||
empty strings. The elements of both sequences must be hashable.
|
empty strings. The elements of both sequences must be :term:`hashable`.
|
||||||
|
|
||||||
:class:`SequenceMatcher` objects have the following methods:
|
:class:`SequenceMatcher` objects have the following methods:
|
||||||
|
|
||||||
|
|
|
@ -747,9 +747,9 @@ available. They are listed here in alphabetical order.
|
||||||
value of ``None`` (if no newlines have been seen yet), ``'\n'``,
|
value of ``None`` (if no newlines have been seen yet), ``'\n'``,
|
||||||
``'\r'``, ``'\r\n'``, or a tuple containing all the newline types seen.
|
``'\r'``, ``'\r\n'``, or a tuple containing all the newline types seen.
|
||||||
|
|
||||||
See also the :mod:`fileinput` module, the file-related functions in the
|
Python provides many file handling modules including
|
||||||
:mod:`os` module, and the :mod:`os.path` module.
|
:mod:`fileinput`, :mod:`os`, :mod:`os.path`, :mod:`tempfile`, and
|
||||||
|
:mod:`shutil`.
|
||||||
|
|
||||||
.. function:: ord(c)
|
.. function:: ord(c)
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,9 @@ functionality than importing a operating system dependent built-in module like
|
||||||
:mod:`posix` or :mod:`nt`. If you just want to read or write a file see
|
:mod:`posix` or :mod:`nt`. If you just want to read or write a file see
|
||||||
:func:`open`, if you want to manipulate paths, see the :mod:`os.path`
|
:func:`open`, if you want to manipulate paths, see the :mod:`os.path`
|
||||||
module, and if you want to read all the lines in all the files on the
|
module, and if you want to read all the lines in all the files on the
|
||||||
command line see the :mod:`fileinput` module.
|
command line see the :mod:`fileinput` module. For creating temporary
|
||||||
|
files and directories see the :mod:`tempfile` module, and for high-level
|
||||||
|
file and directory handling see the :mod:`shutil` module.
|
||||||
|
|
||||||
This module searches for an operating system dependent built-in module like
|
This module searches for an operating system dependent built-in module like
|
||||||
:mod:`mac` or :mod:`posix` and exports the same functions and data as found
|
:mod:`mac` or :mod:`posix` and exports the same functions and data as found
|
||||||
|
@ -800,8 +802,9 @@ Files and Directories
|
||||||
|
|
||||||
.. function:: lstat(path)
|
.. function:: lstat(path)
|
||||||
|
|
||||||
Like :func:`stat`, but do not follow symbolic links. Availability: Macintosh,
|
Like :func:`stat`, but do not follow symbolic links. This is an alias for
|
||||||
Unix.
|
:func:`stat` on platforms that do not support symbolic links, such as
|
||||||
|
Windows.
|
||||||
|
|
||||||
|
|
||||||
.. function:: mkfifo(path[, mode])
|
.. function:: mkfifo(path[, mode])
|
||||||
|
@ -852,6 +855,9 @@ Files and Directories
|
||||||
``0777`` (octal). On some systems, *mode* is ignored. Where it is used, the
|
``0777`` (octal). On some systems, *mode* is ignored. Where it is used, the
|
||||||
current umask value is first masked out. Availability: Macintosh, Unix, Windows.
|
current umask value is first masked out. Availability: Macintosh, Unix, Windows.
|
||||||
|
|
||||||
|
It is also possible to create temporary directories; see the
|
||||||
|
:mod:`tempfile` module's :func:`tempfile.mkdtemp` function.
|
||||||
|
|
||||||
|
|
||||||
.. function:: makedirs(path[, mode])
|
.. function:: makedirs(path[, mode])
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ Bookkeeping functions:
|
||||||
.. function:: seed([x])
|
.. function:: seed([x])
|
||||||
|
|
||||||
Initialize the basic random number generator. Optional argument *x* can be any
|
Initialize the basic random number generator. Optional argument *x* can be any
|
||||||
hashable object. If *x* is omitted or ``None``, current system time is used;
|
:term:`hashable` object. If *x* is omitted or ``None``, current system time is used;
|
||||||
current system time is also used to initialize the generator when the module is
|
current system time is also used to initialize the generator when the module is
|
||||||
first imported. If randomness sources are provided by the operating system,
|
first imported. If randomness sources are provided by the operating system,
|
||||||
they are used instead of the system time (see the :func:`os.urandom` function
|
they are used instead of the system time (see the :func:`os.urandom` function
|
||||||
|
@ -140,7 +140,7 @@ Functions for sequences:
|
||||||
(the sample) to be partitioned into grand prize and second place winners (the
|
(the sample) to be partitioned into grand prize and second place winners (the
|
||||||
subslices).
|
subslices).
|
||||||
|
|
||||||
Members of the population need not be hashable or unique. If the population
|
Members of the population need not be :term:`hashable` or unique. If the population
|
||||||
contains repeats, then each occurrence is a possible selection in the sample.
|
contains repeats, then each occurrence is a possible selection in the sample.
|
||||||
|
|
||||||
To choose a sample from a range of integers, use an :func:`range` object as an
|
To choose a sample from a range of integers, use an :func:`range` object as an
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
|
|
||||||
The :mod:`shutil` module offers a number of high-level operations on files and
|
The :mod:`shutil` module offers a number of high-level operations on files and
|
||||||
collections of files. In particular, functions are provided which support file
|
collections of files. In particular, functions are provided which support file
|
||||||
copying and removal.
|
copying and removal. For operations on individual files, see also the
|
||||||
|
:mod:`os` module.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
|
|
|
@ -874,7 +874,7 @@ functions based on regular expressions.
|
||||||
specified, then there is no limit on the number of splits (all possible
|
specified, then there is no limit on the number of splits (all possible
|
||||||
splits are made).
|
splits are made).
|
||||||
|
|
||||||
If *sep is given, consecutive delimiters are not grouped together and are
|
If *sep* is given, consecutive delimiters are not grouped together and are
|
||||||
deemed to delimit empty strings (for example, ``'1,,2'.split(',')`` returns
|
deemed to delimit empty strings (for example, ``'1,,2'.split(',')`` returns
|
||||||
``['1', '', '2']``). The *sep* argument may consist of multiple characters
|
``['1', '', '2']``). The *sep* argument may consist of multiple characters
|
||||||
(for example, ``'1<>2<>3'.split('<>')`` returns ``['1', '2', '3']``).
|
(for example, ``'1<>2<>3'.split('<>')`` returns ``['1', '2', '3']``).
|
||||||
|
@ -1371,7 +1371,7 @@ Set Types --- :class:`set`, :class:`frozenset`
|
||||||
|
|
||||||
.. index:: object: set
|
.. index:: object: set
|
||||||
|
|
||||||
A :dfn:`set` object is an unordered collection of distinct hashable objects.
|
A :dfn:`set` object is an unordered collection of distinct :term:`hashable` objects.
|
||||||
Common uses include membership testing, removing duplicates from a sequence, and
|
Common uses include membership testing, removing duplicates from a sequence, and
|
||||||
computing mathematical operations such as intersection, union, difference, and
|
computing mathematical operations such as intersection, union, difference, and
|
||||||
symmetric difference.
|
symmetric difference.
|
||||||
|
@ -1387,7 +1387,7 @@ There are currently two builtin set types, :class:`set` and :class:`frozenset`.
|
||||||
The :class:`set` type is mutable --- the contents can be changed using methods
|
The :class:`set` type is mutable --- the contents can be changed using methods
|
||||||
like :meth:`add` and :meth:`remove`. Since it is mutable, it has no hash value
|
like :meth:`add` and :meth:`remove`. Since it is mutable, it has no hash value
|
||||||
and cannot be used as either a dictionary key or as an element of another set.
|
and cannot be used as either a dictionary key or as an element of another set.
|
||||||
The :class:`frozenset` type is immutable and hashable --- its contents cannot be
|
The :class:`frozenset` type is immutable and :term:`hashable` --- its contents cannot be
|
||||||
altered after it is created; it can therefore be used as a dictionary key or as
|
altered after it is created; it can therefore be used as a dictionary key or as
|
||||||
an element of another set.
|
an element of another set.
|
||||||
|
|
||||||
|
@ -1487,8 +1487,7 @@ or ``a>b``. Accordingly, sets do not implement the :meth:`__cmp__` method.
|
||||||
Since sets only define partial ordering (subset relationships), the output of
|
Since sets only define partial ordering (subset relationships), the output of
|
||||||
the :meth:`list.sort` method is undefined for lists of sets.
|
the :meth:`list.sort` method is undefined for lists of sets.
|
||||||
|
|
||||||
Set elements are like dictionary keys; they need to define both :meth:`__hash__`
|
Set elements, like dictionary keys, must be :term:`hashable`.
|
||||||
and :meth:`__eq__` methods.
|
|
||||||
|
|
||||||
Binary operations that mix :class:`set` instances with :class:`frozenset` return
|
Binary operations that mix :class:`set` instances with :class:`frozenset` return
|
||||||
the type of the first operand. For example: ``frozenset('ab') | set('bc')``
|
the type of the first operand. For example: ``frozenset('ab') | set('bc')``
|
||||||
|
@ -1559,20 +1558,20 @@ Mapping Types --- :class:`dict`
|
||||||
statement: del
|
statement: del
|
||||||
builtin: len
|
builtin: len
|
||||||
|
|
||||||
A :dfn:`mapping` object maps immutable values to arbitrary objects. Mappings
|
A :dfn:`mapping` object maps :term:`hashable` values to arbitrary objects.
|
||||||
are mutable objects. There is currently only one standard mapping type, the
|
Mappings are mutable objects. There is currently only one standard mapping
|
||||||
:dfn:`dictionary`.
|
type, the :dfn:`dictionary`. (For other containers see the built in
|
||||||
(For other containers see the built in :class:`list`,
|
:class:`list`, :class:`set`, and :class:`tuple` classes, and the
|
||||||
:class:`set`, and :class:`tuple` classes, and the :mod:`collections`
|
:mod:`collections` module.)
|
||||||
module.)
|
|
||||||
|
|
||||||
A dictionary's keys are *almost* arbitrary values. Only values containing
|
A dictionary's keys are *almost* arbitrary values. Values that are not
|
||||||
lists, dictionaries or other mutable types (that are compared by value rather
|
:term:`hashable`, that is, values containing lists, dictionaries or other
|
||||||
than by object identity) may not be used as keys. Numeric types used for keys
|
mutable types (that are compared by value rather than by object identity) may
|
||||||
obey the normal rules for numeric comparison: if two numbers compare equal (such
|
not be used as keys. Numeric types used for keys obey the normal rules for
|
||||||
as ``1`` and ``1.0``) then they can be used interchangeably to index the same
|
numeric comparison: if two numbers compare equal (such as ``1`` and ``1.0``)
|
||||||
dictionary entry. (Note however, that since computers store floating-point
|
then they can be used interchangeably to index the same dictionary entry. (Note
|
||||||
numbers as approximations it is usually unwise to use them as dictionary keys.)
|
however, that since computers store floating-point numbers as approximations it
|
||||||
|
is usually unwise to use them as dictionary keys.)
|
||||||
|
|
||||||
Dictionaries can be created by placing a comma-separated list of ``key: value``
|
Dictionaries can be created by placing a comma-separated list of ``key: value``
|
||||||
pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
|
pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
|
||||||
|
@ -1821,7 +1820,10 @@ created with the built-in :func:`file` and (more usually) :func:`open`
|
||||||
constructors described in the :ref:`built-in-funcs` section. [#]_ File
|
constructors described in the :ref:`built-in-funcs` section. [#]_ File
|
||||||
objects are also returned by some other built-in functions and methods,
|
objects are also returned by some other built-in functions and methods,
|
||||||
such as :func:`os.popen` and :func:`os.fdopen` and the :meth:`makefile`
|
such as :func:`os.popen` and :func:`os.fdopen` and the :meth:`makefile`
|
||||||
method of socket objects.
|
method of socket objects. Temporary files can be created using the
|
||||||
|
:mod:`tempfile` module, and high-level file operations such as copying,
|
||||||
|
moving, and deleting files and directories can be achieved with the
|
||||||
|
:mod:`shutil` module.
|
||||||
|
|
||||||
When a file operation fails for an I/O-related reason, the exception
|
When a file operation fails for an I/O-related reason, the exception
|
||||||
:exc:`IOError` is raised. This includes situations where the operation is not
|
:exc:`IOError` is raised. This includes situations where the operation is not
|
||||||
|
|
|
@ -85,7 +85,7 @@ Extension types can easily be made to support weak references; see
|
||||||
but cannot be propagated; they are handled in exactly the same way as exceptions
|
but cannot be propagated; they are handled in exactly the same way as exceptions
|
||||||
raised from an object's :meth:`__del__` method.
|
raised from an object's :meth:`__del__` method.
|
||||||
|
|
||||||
Weak references are hashable if the *object* is hashable. They will maintain
|
Weak references are :term:`hashable` if the *object* is hashable. They will maintain
|
||||||
their hash value even after the *object* was deleted. If :func:`hash` is called
|
their hash value even after the *object* was deleted. If :func:`hash` is called
|
||||||
the first time only after the *object* was deleted, the call will raise
|
the first time only after the *object* was deleted, the call will raise
|
||||||
:exc:`TypeError`.
|
:exc:`TypeError`.
|
||||||
|
@ -104,7 +104,7 @@ Extension types can easily be made to support weak references; see
|
||||||
the proxy in most contexts instead of requiring the explicit dereferencing used
|
the proxy in most contexts instead of requiring the explicit dereferencing used
|
||||||
with weak reference objects. The returned object will have a type of either
|
with weak reference objects. The returned object will have a type of either
|
||||||
``ProxyType`` or ``CallableProxyType``, depending on whether *object* is
|
``ProxyType`` or ``CallableProxyType``, depending on whether *object* is
|
||||||
callable. Proxy objects are not hashable regardless of the referent; this
|
callable. Proxy objects are not :term:`hashable` regardless of the referent; this
|
||||||
avoids a number of problems related to their fundamentally mutable nature, and
|
avoids a number of problems related to their fundamentally mutable nature, and
|
||||||
prevent their use as dictionary keys. *callback* is the same as the parameter
|
prevent their use as dictionary keys. *callback* is the same as the parameter
|
||||||
of the same name to the :func:`ref` function.
|
of the same name to the :func:`ref` function.
|
||||||
|
|
|
@ -388,9 +388,10 @@ Set types
|
||||||
Frozen sets
|
Frozen sets
|
||||||
.. index:: object: frozenset
|
.. index:: object: frozenset
|
||||||
|
|
||||||
These represent an immutable set. They are created by the built-in
|
These represent an immutable set. They are created by the built-in
|
||||||
:func:`frozenset` constructor. As a frozenset is immutable and hashable, it can
|
:func:`frozenset` constructor. As a frozenset is immutable and
|
||||||
be used again as an element of another set, or as a dictionary key.
|
:term:`hashable`, it can be used again as an element of another set, or as
|
||||||
|
a dictionary key.
|
||||||
|
|
||||||
.. % Set types
|
.. % Set types
|
||||||
|
|
||||||
|
@ -1242,6 +1243,9 @@ Basic customization
|
||||||
object.__gt__(self, other)
|
object.__gt__(self, other)
|
||||||
object.__ge__(self, other)
|
object.__ge__(self, other)
|
||||||
|
|
||||||
|
.. index::
|
||||||
|
single: comparisons
|
||||||
|
|
||||||
These are the so-called "rich comparison" methods, and are called for comparison
|
These are the so-called "rich comparison" methods, and are called for comparison
|
||||||
operators in preference to :meth:`__cmp__` below. The correspondence between
|
operators in preference to :meth:`__cmp__` below. The correspondence between
|
||||||
operator symbols and method names is as follows: ``x<y`` calls ``x.__lt__(y)``,
|
operator symbols and method names is as follows: ``x<y`` calls ``x.__lt__(y)``,
|
||||||
|
@ -1256,14 +1260,16 @@ Basic customization
|
||||||
context (e.g., in the condition of an ``if`` statement), Python will call
|
context (e.g., in the condition of an ``if`` statement), Python will call
|
||||||
:func:`bool` on the value to determine if the result is true or false.
|
:func:`bool` on the value to determine if the result is true or false.
|
||||||
|
|
||||||
There are no implied relationships among the comparison operators. The truth of
|
There are no implied relationships among the comparison operators. The truth
|
||||||
``x==y`` does not imply that ``x!=y`` is false. Accordingly, when defining
|
of ``x==y`` does not imply that ``x!=y`` is false. Accordingly, when
|
||||||
:meth:`__eq__`, one should also define :meth:`__ne__` so that the operators will
|
defining :meth:`__eq__`, one should also define :meth:`__ne__` so that the
|
||||||
behave as expected.
|
operators will behave as expected. See the paragraph on :meth:`__hash__` for
|
||||||
|
some important notes on creating :term:`hashable` objects which support
|
||||||
|
custom comparison operations and are usable as dictionary keys.
|
||||||
|
|
||||||
There are no reflected (swapped-argument) versions of these methods (to be used
|
There are no swapped-argument versions of these methods (to be used when the
|
||||||
when the left argument does not support the operation but the right argument
|
left argument does not support the operation but the right argument does);
|
||||||
does); rather, :meth:`__lt__` and :meth:`__gt__` are each other's reflection,
|
rather, :meth:`__lt__` and :meth:`__gt__` are each other's reflection,
|
||||||
:meth:`__le__` and :meth:`__ge__` are each other's reflection, and
|
:meth:`__le__` and :meth:`__ge__` are each other's reflection, and
|
||||||
:meth:`__eq__` and :meth:`__ne__` are their own reflection.
|
:meth:`__eq__` and :meth:`__ne__` are their own reflection.
|
||||||
|
|
||||||
|
@ -1276,14 +1282,15 @@ Basic customization
|
||||||
builtin: cmp
|
builtin: cmp
|
||||||
single: comparisons
|
single: comparisons
|
||||||
|
|
||||||
Called by comparison operations if rich comparison (see above) is not defined.
|
Called by comparison operations if rich comparison (see above) is not
|
||||||
Should return a negative integer if ``self < other``, zero if ``self == other``,
|
defined. Should return a negative integer if ``self < other``, zero if
|
||||||
a positive integer if ``self > other``. If no :meth:`__cmp__`, :meth:`__eq__`
|
``self == other``, a positive integer if ``self > other``. If no
|
||||||
or :meth:`__ne__` operation is defined, class instances are compared by object
|
:meth:`__cmp__`, :meth:`__eq__` or :meth:`__ne__` operation is defined, class
|
||||||
identity ("address"). See also the description of :meth:`__hash__` for some
|
instances are compared by object identity ("address"). See also the
|
||||||
important notes on creating objects which support custom comparison operations
|
description of :meth:`__hash__` for some important notes on creating
|
||||||
and are usable as dictionary keys. (Note: the restriction that exceptions are
|
:term:`hashable` objects which support custom comparison operations and are
|
||||||
not propagated by :meth:`__cmp__` has been removed since Python 1.5.)
|
usable as dictionary keys. (Note: the restriction that exceptions are not
|
||||||
|
propagated by :meth:`__cmp__` has been removed since Python 1.5.)
|
||||||
|
|
||||||
|
|
||||||
.. method:: object.__hash__(self)
|
.. method:: object.__hash__(self)
|
||||||
|
@ -1293,19 +1300,12 @@ Basic customization
|
||||||
builtin: hash
|
builtin: hash
|
||||||
single: __cmp__() (object method)
|
single: __cmp__() (object method)
|
||||||
|
|
||||||
Called for the key object for dictionary operations, and by the built-in
|
Called for the key object for dictionary operations, and by the built-in
|
||||||
function :func:`hash`. Should return a 32-bit integer usable as a hash value
|
function :func:`hash`. Should return an integer usable as a hash value
|
||||||
for dictionary operations. The only required property is that objects which
|
for dictionary operations. The only required property is that objects which
|
||||||
compare equal have the same hash value; it is advised to somehow mix together
|
compare equal have the same hash value; it is advised to somehow mix together
|
||||||
(e.g., using exclusive or) the hash values for the components of the object that
|
(e.g., using exclusive or) the hash values for the components of the object that
|
||||||
also play a part in comparison of objects. If a class does not define a
|
also play a part in comparison of objects.
|
||||||
:meth:`__cmp__` method it should not define a :meth:`__hash__` operation either;
|
|
||||||
if it defines :meth:`__cmp__` or :meth:`__eq__` but not :meth:`__hash__`, its
|
|
||||||
instances will not be usable as dictionary keys. If a class defines mutable
|
|
||||||
objects and implements a :meth:`__cmp__` or :meth:`__eq__` method, it should not
|
|
||||||
implement :meth:`__hash__`, since the dictionary implementation requires that a
|
|
||||||
key's hash value is immutable (if the object's hash value changes, it will be in
|
|
||||||
the wrong hash bucket).
|
|
||||||
|
|
||||||
:meth:`__hash__` may also return a long integer object; the 32-bit integer is
|
:meth:`__hash__` may also return a long integer object; the 32-bit integer is
|
||||||
then derived from the hash of that object.
|
then derived from the hash of that object.
|
||||||
|
|
|
@ -267,7 +267,7 @@ in the new dictionary in the order they are produced.
|
||||||
hashable
|
hashable
|
||||||
|
|
||||||
Restrictions on the types of the key values are listed earlier in section
|
Restrictions on the types of the key values are listed earlier in section
|
||||||
:ref:`types`. (To summarize, the key type should be hashable, which excludes
|
:ref:`types`. (To summarize, the key type should be :term:`hashable`, which excludes
|
||||||
all mutable objects.) Clashes between duplicate keys are not detected; the last
|
all mutable objects.) Clashes between duplicate keys are not detected; the last
|
||||||
datum (textually rightmost in the display) stored for a given key value
|
datum (textually rightmost in the display) stored for a given key value
|
||||||
prevails.
|
prevails.
|
||||||
|
|
|
@ -362,7 +362,7 @@ def __new_rowid(self, table, txn) :
|
||||||
unique = 0
|
unique = 0
|
||||||
while not unique:
|
while not unique:
|
||||||
# Generate a random 64-bit row ID string
|
# Generate a random 64-bit row ID string
|
||||||
# (note: might have <64 bits of randomness
|
# (note: might have <64 bits of true randomness
|
||||||
# but it's plenty for our database id needs!)
|
# but it's plenty for our database id needs!)
|
||||||
blist = []
|
blist = []
|
||||||
for x in range(_rowid_str_len):
|
for x in range(_rowid_str_len):
|
||||||
|
|
|
@ -25,6 +25,10 @@ def __exit__(self, type, value, traceback):
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("generator didn't stop")
|
raise RuntimeError("generator didn't stop")
|
||||||
else:
|
else:
|
||||||
|
if value is None:
|
||||||
|
# Need to force instantiation so we can reliably
|
||||||
|
# tell if we get the same exception back
|
||||||
|
value = type()
|
||||||
try:
|
try:
|
||||||
self.gen.throw(type, value, traceback)
|
self.gen.throw(type, value, traceback)
|
||||||
raise RuntimeError("generator didn't stop after throw()")
|
raise RuntimeError("generator didn't stop after throw()")
|
||||||
|
|
|
@ -158,17 +158,17 @@ def test_double_plus(self):
|
||||||
self.failUnlessEqual(self._dll.tf_bd(0, 42.), 14.)
|
self.failUnlessEqual(self._dll.tf_bd(0, 42.), 14.)
|
||||||
self.failUnlessEqual(self.S(), 42)
|
self.failUnlessEqual(self.S(), 42)
|
||||||
|
|
||||||
## def test_longdouble(self):
|
def test_longdouble(self):
|
||||||
## self._dll.tf_D.restype = c_longdouble
|
self._dll.tf_D.restype = c_longdouble
|
||||||
## self._dll.tf_D.argtypes = (c_longdouble,)
|
self._dll.tf_D.argtypes = (c_longdouble,)
|
||||||
## self.failUnlessEqual(self._dll.tf_D(42.), 14.)
|
self.failUnlessEqual(self._dll.tf_D(42.), 14.)
|
||||||
## self.failUnlessEqual(self.S(), 42)
|
self.failUnlessEqual(self.S(), 42)
|
||||||
|
|
||||||
## def test_longdouble_plus(self):
|
def test_longdouble_plus(self):
|
||||||
## self._dll.tf_bD.restype = c_longdouble
|
self._dll.tf_bD.restype = c_longdouble
|
||||||
## self._dll.tf_bD.argtypes = (c_byte, c_longdouble)
|
self._dll.tf_bD.argtypes = (c_byte, c_longdouble)
|
||||||
## self.failUnlessEqual(self._dll.tf_bD(0, 42.), 14.)
|
self.failUnlessEqual(self._dll.tf_bD(0, 42.), 14.)
|
||||||
## self.failUnlessEqual(self.S(), 42)
|
self.failUnlessEqual(self.S(), 42)
|
||||||
|
|
||||||
def test_callwithresult(self):
|
def test_callwithresult(self):
|
||||||
def process_result(result):
|
def process_result(result):
|
||||||
|
|
|
@ -143,17 +143,17 @@ def test_doubleresult(self):
|
||||||
self.failUnlessEqual(result, -21)
|
self.failUnlessEqual(result, -21)
|
||||||
self.failUnlessEqual(type(result), float)
|
self.failUnlessEqual(type(result), float)
|
||||||
|
|
||||||
## def test_longdoubleresult(self):
|
def test_longdoubleresult(self):
|
||||||
## f = dll._testfunc_D_bhilfD
|
f = dll._testfunc_D_bhilfD
|
||||||
## f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble]
|
f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_longdouble]
|
||||||
## f.restype = c_longdouble
|
f.restype = c_longdouble
|
||||||
## result = f(1, 2, 3, 4, 5.0, 6.0)
|
result = f(1, 2, 3, 4, 5.0, 6.0)
|
||||||
## self.failUnlessEqual(result, 21)
|
self.failUnlessEqual(result, 21)
|
||||||
## self.failUnlessEqual(type(result), float)
|
self.failUnlessEqual(type(result), float)
|
||||||
|
|
||||||
## result = f(-1, -2, -3, -4, -5.0, -6.0)
|
result = f(-1, -2, -3, -4, -5.0, -6.0)
|
||||||
## self.failUnlessEqual(result, -21)
|
self.failUnlessEqual(result, -21)
|
||||||
## self.failUnlessEqual(type(result), float)
|
self.failUnlessEqual(type(result), float)
|
||||||
|
|
||||||
def test_longlongresult(self):
|
def test_longlongresult(self):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -442,6 +442,7 @@ def shouldThrow():
|
||||||
self.assertAfterWithGeneratorInvariantsNoError(self.bar)
|
self.assertAfterWithGeneratorInvariantsNoError(self.bar)
|
||||||
|
|
||||||
def testRaisedStopIteration1(self):
|
def testRaisedStopIteration1(self):
|
||||||
|
# From bug 1462485
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def cm():
|
def cm():
|
||||||
yield
|
yield
|
||||||
|
@ -453,6 +454,7 @@ def shouldThrow():
|
||||||
self.assertRaises(StopIteration, shouldThrow)
|
self.assertRaises(StopIteration, shouldThrow)
|
||||||
|
|
||||||
def testRaisedStopIteration2(self):
|
def testRaisedStopIteration2(self):
|
||||||
|
# From bug 1462485
|
||||||
class cm(object):
|
class cm(object):
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
pass
|
pass
|
||||||
|
@ -465,7 +467,21 @@ def shouldThrow():
|
||||||
|
|
||||||
self.assertRaises(StopIteration, shouldThrow)
|
self.assertRaises(StopIteration, shouldThrow)
|
||||||
|
|
||||||
|
def testRaisedStopIteration3(self):
|
||||||
|
# Another variant where the exception hasn't been instantiated
|
||||||
|
# From bug 1705170
|
||||||
|
@contextmanager
|
||||||
|
def cm():
|
||||||
|
yield
|
||||||
|
|
||||||
|
def shouldThrow():
|
||||||
|
with cm():
|
||||||
|
raise next(iter([]))
|
||||||
|
|
||||||
|
self.assertRaises(StopIteration, shouldThrow)
|
||||||
|
|
||||||
def testRaisedGeneratorExit1(self):
|
def testRaisedGeneratorExit1(self):
|
||||||
|
# From bug 1462485
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def cm():
|
def cm():
|
||||||
yield
|
yield
|
||||||
|
@ -477,6 +493,7 @@ def shouldThrow():
|
||||||
self.assertRaises(GeneratorExit, shouldThrow)
|
self.assertRaises(GeneratorExit, shouldThrow)
|
||||||
|
|
||||||
def testRaisedGeneratorExit2(self):
|
def testRaisedGeneratorExit2(self):
|
||||||
|
# From bug 1462485
|
||||||
class cm (object):
|
class cm (object):
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -5920,6 +5920,10 @@ PyMODINIT_FUNC init_bsddb(void)
|
||||||
ADD_INT(d, DB_NOPANIC);
|
ADD_INT(d, DB_NOPANIC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef DB_REGISTER
|
||||||
|
ADD_INT(d, DB_REGISTER);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if (DBVER >= 42)
|
#if (DBVER >= 42)
|
||||||
ADD_INT(d, DB_TIME_NOTGRANTED);
|
ADD_INT(d, DB_TIME_NOTGRANTED);
|
||||||
ADD_INT(d, DB_TXN_NOT_DURABLE);
|
ADD_INT(d, DB_TXN_NOT_DURABLE);
|
||||||
|
|
3
configure
vendored
3
configure
vendored
|
@ -13315,7 +13315,10 @@ fi
|
||||||
|
|
||||||
if test -z "$with_system_ffi" && test "$ac_cv_header_ffi_h" = yes; then
|
if test -z "$with_system_ffi" && test "$ac_cv_header_ffi_h" = yes; then
|
||||||
case "$ac_sys_system/`uname -m`" in
|
case "$ac_sys_system/`uname -m`" in
|
||||||
|
Linux/alpha*) with_system_ffi="yes"; CONFIG_ARGS="$CONFIG_ARGS --with-system-ffi";;
|
||||||
Linux/arm*) with_system_ffi="yes"; CONFIG_ARGS="$CONFIG_ARGS --with-system-ffi";;
|
Linux/arm*) with_system_ffi="yes"; CONFIG_ARGS="$CONFIG_ARGS --with-system-ffi";;
|
||||||
|
Linux/ppc*) with_system_ffi="yes"; CONFIG_ARGS="$CONFIG_ARGS --with-system-ffi";;
|
||||||
|
Linux/s390*) with_system_ffi="yes"; CONFIG_ARGS="$CONFIG_ARGS --with-system-ffi";;
|
||||||
*) with_system_ffi="no"
|
*) with_system_ffi="no"
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1731,7 +1731,10 @@ AC_ARG_WITH(system_ffi,
|
||||||
|
|
||||||
if test -z "$with_system_ffi" && test "$ac_cv_header_ffi_h" = yes; then
|
if test -z "$with_system_ffi" && test "$ac_cv_header_ffi_h" = yes; then
|
||||||
case "$ac_sys_system/`uname -m`" in
|
case "$ac_sys_system/`uname -m`" in
|
||||||
|
Linux/alpha*) with_system_ffi="yes"; CONFIG_ARGS="$CONFIG_ARGS --with-system-ffi";;
|
||||||
Linux/arm*) with_system_ffi="yes"; CONFIG_ARGS="$CONFIG_ARGS --with-system-ffi";;
|
Linux/arm*) with_system_ffi="yes"; CONFIG_ARGS="$CONFIG_ARGS --with-system-ffi";;
|
||||||
|
Linux/ppc*) with_system_ffi="yes"; CONFIG_ARGS="$CONFIG_ARGS --with-system-ffi";;
|
||||||
|
Linux/s390*) with_system_ffi="yes"; CONFIG_ARGS="$CONFIG_ARGS --with-system-ffi";;
|
||||||
*) with_system_ffi="no"
|
*) with_system_ffi="no"
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue