benjamin.peterson
2008-09-03 22:22:18 UTC
Author: benjamin.peterson
Date: Thu Sep 4 00:22:18 2008
New Revision: 66194
Log:
Merged revisions 66134,66136,66143,66154-66155,66190 via svnmerge from
svn+ssh://pythondev at svn.python.org/python/trunk
........
r66134 | andrew.kuchling | 2008-09-01 20:13:42 -0500 (Mon, 01 Sep 2008) | 1 line
Describe the __hash__ changes
........
r66136 | andrew.kuchling | 2008-09-01 20:39:18 -0500 (Mon, 01 Sep 2008) | 1 line
typo fix
........
r66143 | mark.summerfield | 2008-09-02 02:23:16 -0500 (Tue, 02 Sep 2008) | 3 lines
a typo
........
r66154 | andrew.kuchling | 2008-09-02 08:06:00 -0500 (Tue, 02 Sep 2008) | 1 line
Clarify example; add imports
........
r66155 | andrew.kuchling | 2008-09-02 08:08:11 -0500 (Tue, 02 Sep 2008) | 1 line
Add e-mail address
........
r66190 | benjamin.peterson | 2008-09-03 16:48:20 -0500 (Wed, 03 Sep 2008) | 1 line
3.0 still has the old threading names
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Doc/library/warnings.rst
python/branches/py3k/Doc/whatsnew/2.6.rst
Modified: python/branches/py3k/Doc/library/warnings.rst
==============================================================================
--- python/branches/py3k/Doc/library/warnings.rst (original)
+++ python/branches/py3k/Doc/library/warnings.rst Thu Sep 4 00:22:18 2008
@@ -253,7 +253,7 @@
.. class:: catch_warnings([\*, record=False, module=None])
- A context manager that guards the warnings filter from being permanentally
+ A context manager that guards the warnings filter from being permanently
mutated. The manager returns an instance of :class:`WarningsRecorder`. The
*record* argument specifies whether warnings that would typically be
handled by :func:`showwarning` should instead be recorded by the
Modified: python/branches/py3k/Doc/whatsnew/2.6.rst
==============================================================================
--- python/branches/py3k/Doc/whatsnew/2.6.rst (original)
+++ python/branches/py3k/Doc/whatsnew/2.6.rst Thu Sep 4 00:22:18 2008
@@ -4,7 +4,7 @@
.. XXX add trademark info for Apple, Microsoft, SourceForge.
-:Author: A.M. Kuchling
+:Author: A.M. Kuchling (amk at amk.ca)
:Release: |release|
:Date: |today|
@@ -203,7 +203,7 @@
started around 1989. In the 1980s and early 1990s, most documentation
was printed out for later study, not viewed online. LaTeX was widely
used because it provided attractive printed output while remaining
-straightforward to write once the basic rules of the markup werw
+straightforward to write once the basic rules of the markup were
learned.
Today LaTeX is still used for writing publications destined for
@@ -1224,7 +1224,7 @@
You can write your own ABCs by using ``abc.ABCMeta`` as the
metaclass in a class definition::
- from abc import ABCMeta
+ from abc import ABCMeta, abstractmethod
class Drawable():
__metaclass__ = ABCMeta
@@ -1256,15 +1256,21 @@
Note that the exception is only raised when you actually
try to create an instance of a subclass lacking the method::
- >>> s=Square()
+ >>> class Circle(Drawable):
+ ... pass
+ ...
+ >>> c=Circle()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
- TypeError: Can't instantiate abstract class Square with abstract methods draw
+ TypeError: Can't instantiate abstract class Circle with abstract methods draw
Abstract data attributes can be declared using the
``@abstractproperty`` decorator::
+ from abc import abstractproperty
+ ...
+
@abstractproperty
def readonly(self):
return self._x
@@ -1595,6 +1601,22 @@
:func:`complex` constructor will now preserve the sign
of the zero. (Fixed by Mark T. Dickinson; :issue:`1507`.)
+* Classes that inherit a :meth:`__hash__` method from a parent class
+ can set ``__hash__ = None`` to indicate that the class isn't
+ hashable. This will make ``hash(obj)`` raise a :exc:`TypeError`
+ and the class will not be indicated as implementing the
+ :class:`Hashable` ABC.
+
+ You should do this when you've defined a :meth:`__cmp__` or
+ :meth:`__eq__` method that compares objects by their value rather
+ than by identity. All objects have a default hash method that uses
+ ``id(obj)`` as the hash value. There's no tidy way to remove the
+ :meth:`__hash__` method inherited from a parent class, so
+ assigning ``None`` was implemented as an override. At the
+ C level, extensions can set ``tp_hash`` to
+ :cfunc:`PyObject_HashNotImplemented`.
+ (Fixed by Nick Coghlan and Amaury Forgeot d'Arc; :issue:`2235`.)
+
* Changes to the :class:`Exception` interface
as dictated by :pep:`352` continue to be made. For 2.6,
the :attr:`message` attribute is being deprecated in favor of the
@@ -2501,14 +2523,14 @@
(Contributed by Dwayne Bailey; :issue:`1581073`.)
-* The :mod:`threading` module API is being changed in Python 3.0 to
- use properties such as :attr:`daemon` instead of :meth:`setDaemon`
- and :meth:`isDaemon` methods, and some methods have been renamed to
- use underscores instead of camel-case; for example, the
- :meth:`activeCount` method is renamed to :meth:`active_count`. The
- 2.6 version of the module supports the same properties and renamed
- methods, but doesn't remove the old methods. (Carried out by
- several people, most notably Benjamin Peterson.)
+* The :mod:`threading` module API is being changed to use properties such as
+ :attr:`daemon` instead of :meth:`setDaemon` and :meth:`isDaemon` methods, and
+ some methods have been renamed to use underscores instead of camel-case; for
+ example, the :meth:`activeCount` method is renamed to :meth:`active_count`.
+ The 2.6 version of the module supports the same properties and renamed
+ methods, but doesn't remove the old methods. 3.0 also fully supports both
+ APIs, and a date for the deprecation of the old APIs has not been set yet.
+ (Carried out by several people, most notably Benjamin Peterson.)
The :mod:`threading` module's :class:`Thread` objects
gained an :attr:`ident` property that returns the thread's
@@ -3125,6 +3147,10 @@
This section lists previously described changes and other bugfixes
that may require changes to your code:
+* Classes that aren't supposed to be hashable should
+ set ``__hash__ = None`` in their definitions to indicate
+ the fact.
+
* The :meth:`__init__` method of :class:`collections.deque`
now clears any existing contents of the deque
before adding elements from the iterable. This change makes the
@@ -3147,6 +3173,10 @@
functions now default to absolute imports, not relative imports.
This will affect C extensions that import other modules.
+* C API: extension data types that shouldn't be hashable
+ should define their ``tp_hash`` slot to
+ :cfunc:`PyObject_HashNotImplemented`.
+
* The :mod:`socket` module exception :exc:`socket.error` now inherits
from :exc:`IOError`. Previously it wasn't a subclass of
:exc:`StandardError` but now it is, through :exc:`IOError`.
@@ -3182,5 +3212,5 @@
The author would like to thank the following people for offering suggestions,
corrections and assistance with various drafts of this article:
-Georg Brandl, Jim Jewett, Antoine Pitrou.
+Georg Brandl, Steve Brown, Nick Coghlan, Jim Jewett, Antoine Pitrou.
Date: Thu Sep 4 00:22:18 2008
New Revision: 66194
Log:
Merged revisions 66134,66136,66143,66154-66155,66190 via svnmerge from
svn+ssh://pythondev at svn.python.org/python/trunk
........
r66134 | andrew.kuchling | 2008-09-01 20:13:42 -0500 (Mon, 01 Sep 2008) | 1 line
Describe the __hash__ changes
........
r66136 | andrew.kuchling | 2008-09-01 20:39:18 -0500 (Mon, 01 Sep 2008) | 1 line
typo fix
........
r66143 | mark.summerfield | 2008-09-02 02:23:16 -0500 (Tue, 02 Sep 2008) | 3 lines
a typo
........
r66154 | andrew.kuchling | 2008-09-02 08:06:00 -0500 (Tue, 02 Sep 2008) | 1 line
Clarify example; add imports
........
r66155 | andrew.kuchling | 2008-09-02 08:08:11 -0500 (Tue, 02 Sep 2008) | 1 line
Add e-mail address
........
r66190 | benjamin.peterson | 2008-09-03 16:48:20 -0500 (Wed, 03 Sep 2008) | 1 line
3.0 still has the old threading names
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Doc/library/warnings.rst
python/branches/py3k/Doc/whatsnew/2.6.rst
Modified: python/branches/py3k/Doc/library/warnings.rst
==============================================================================
--- python/branches/py3k/Doc/library/warnings.rst (original)
+++ python/branches/py3k/Doc/library/warnings.rst Thu Sep 4 00:22:18 2008
@@ -253,7 +253,7 @@
.. class:: catch_warnings([\*, record=False, module=None])
- A context manager that guards the warnings filter from being permanentally
+ A context manager that guards the warnings filter from being permanently
mutated. The manager returns an instance of :class:`WarningsRecorder`. The
*record* argument specifies whether warnings that would typically be
handled by :func:`showwarning` should instead be recorded by the
Modified: python/branches/py3k/Doc/whatsnew/2.6.rst
==============================================================================
--- python/branches/py3k/Doc/whatsnew/2.6.rst (original)
+++ python/branches/py3k/Doc/whatsnew/2.6.rst Thu Sep 4 00:22:18 2008
@@ -4,7 +4,7 @@
.. XXX add trademark info for Apple, Microsoft, SourceForge.
-:Author: A.M. Kuchling
+:Author: A.M. Kuchling (amk at amk.ca)
:Release: |release|
:Date: |today|
@@ -203,7 +203,7 @@
started around 1989. In the 1980s and early 1990s, most documentation
was printed out for later study, not viewed online. LaTeX was widely
used because it provided attractive printed output while remaining
-straightforward to write once the basic rules of the markup werw
+straightforward to write once the basic rules of the markup were
learned.
Today LaTeX is still used for writing publications destined for
@@ -1224,7 +1224,7 @@
You can write your own ABCs by using ``abc.ABCMeta`` as the
metaclass in a class definition::
- from abc import ABCMeta
+ from abc import ABCMeta, abstractmethod
class Drawable():
__metaclass__ = ABCMeta
@@ -1256,15 +1256,21 @@
Note that the exception is only raised when you actually
try to create an instance of a subclass lacking the method::
- >>> s=Square()
+ >>> class Circle(Drawable):
+ ... pass
+ ...
+ >>> c=Circle()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
- TypeError: Can't instantiate abstract class Square with abstract methods draw
+ TypeError: Can't instantiate abstract class Circle with abstract methods draw
Abstract data attributes can be declared using the
``@abstractproperty`` decorator::
+ from abc import abstractproperty
+ ...
+
@abstractproperty
def readonly(self):
return self._x
@@ -1595,6 +1601,22 @@
:func:`complex` constructor will now preserve the sign
of the zero. (Fixed by Mark T. Dickinson; :issue:`1507`.)
+* Classes that inherit a :meth:`__hash__` method from a parent class
+ can set ``__hash__ = None`` to indicate that the class isn't
+ hashable. This will make ``hash(obj)`` raise a :exc:`TypeError`
+ and the class will not be indicated as implementing the
+ :class:`Hashable` ABC.
+
+ You should do this when you've defined a :meth:`__cmp__` or
+ :meth:`__eq__` method that compares objects by their value rather
+ than by identity. All objects have a default hash method that uses
+ ``id(obj)`` as the hash value. There's no tidy way to remove the
+ :meth:`__hash__` method inherited from a parent class, so
+ assigning ``None`` was implemented as an override. At the
+ C level, extensions can set ``tp_hash`` to
+ :cfunc:`PyObject_HashNotImplemented`.
+ (Fixed by Nick Coghlan and Amaury Forgeot d'Arc; :issue:`2235`.)
+
* Changes to the :class:`Exception` interface
as dictated by :pep:`352` continue to be made. For 2.6,
the :attr:`message` attribute is being deprecated in favor of the
@@ -2501,14 +2523,14 @@
(Contributed by Dwayne Bailey; :issue:`1581073`.)
-* The :mod:`threading` module API is being changed in Python 3.0 to
- use properties such as :attr:`daemon` instead of :meth:`setDaemon`
- and :meth:`isDaemon` methods, and some methods have been renamed to
- use underscores instead of camel-case; for example, the
- :meth:`activeCount` method is renamed to :meth:`active_count`. The
- 2.6 version of the module supports the same properties and renamed
- methods, but doesn't remove the old methods. (Carried out by
- several people, most notably Benjamin Peterson.)
+* The :mod:`threading` module API is being changed to use properties such as
+ :attr:`daemon` instead of :meth:`setDaemon` and :meth:`isDaemon` methods, and
+ some methods have been renamed to use underscores instead of camel-case; for
+ example, the :meth:`activeCount` method is renamed to :meth:`active_count`.
+ The 2.6 version of the module supports the same properties and renamed
+ methods, but doesn't remove the old methods. 3.0 also fully supports both
+ APIs, and a date for the deprecation of the old APIs has not been set yet.
+ (Carried out by several people, most notably Benjamin Peterson.)
The :mod:`threading` module's :class:`Thread` objects
gained an :attr:`ident` property that returns the thread's
@@ -3125,6 +3147,10 @@
This section lists previously described changes and other bugfixes
that may require changes to your code:
+* Classes that aren't supposed to be hashable should
+ set ``__hash__ = None`` in their definitions to indicate
+ the fact.
+
* The :meth:`__init__` method of :class:`collections.deque`
now clears any existing contents of the deque
before adding elements from the iterable. This change makes the
@@ -3147,6 +3173,10 @@
functions now default to absolute imports, not relative imports.
This will affect C extensions that import other modules.
+* C API: extension data types that shouldn't be hashable
+ should define their ``tp_hash`` slot to
+ :cfunc:`PyObject_HashNotImplemented`.
+
* The :mod:`socket` module exception :exc:`socket.error` now inherits
from :exc:`IOError`. Previously it wasn't a subclass of
:exc:`StandardError` but now it is, through :exc:`IOError`.
@@ -3182,5 +3212,5 @@
The author would like to thank the following people for offering suggestions,
corrections and assistance with various drafts of this article:
-Georg Brandl, Jim Jewett, Antoine Pitrou.
+Georg Brandl, Steve Brown, Nick Coghlan, Jim Jewett, Antoine Pitrou.