Skip to content

Commit dcc1e11

Browse files
committed
Merged revisions 66134,66136,66143,66154-66155,66190 via svnmerge from
svn+ssh://[email protected]/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 ........
1 parent a64072f commit dcc1e11

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

Doc/library/warnings.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ Available Classes
253253

254254
.. class:: catch_warnings([\*, record=False, module=None])
255255

256-
A context manager that guards the warnings filter from being permanentally
256+
A context manager that guards the warnings filter from being permanently
257257
mutated. The manager returns an instance of :class:`WarningsRecorder`. The
258258
*record* argument specifies whether warnings that would typically be
259259
handled by :func:`showwarning` should instead be recorded by the

Doc/whatsnew/2.6.rst

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
.. XXX add trademark info for Apple, Microsoft, SourceForge.
66
7-
:Author: A.M. Kuchling
7+
:Author: A.M. Kuchling (amk at amk.ca)
88
:Release: |release|
99
:Date: |today|
1010

@@ -203,7 +203,7 @@ The Python documentation was written using LaTeX since the project
203203
started around 1989. In the 1980s and early 1990s, most documentation
204204
was printed out for later study, not viewed online. LaTeX was widely
205205
used because it provided attractive printed output while remaining
206-
straightforward to write once the basic rules of the markup werw
206+
straightforward to write once the basic rules of the markup were
207207
learned.
208208

209209
Today LaTeX is still used for writing publications destined for
@@ -1224,7 +1224,7 @@ do it where it's absolutely necessary.
12241224
You can write your own ABCs by using ``abc.ABCMeta`` as the
12251225
metaclass in a class definition::
12261226

1227-
from abc import ABCMeta
1227+
from abc import ABCMeta, abstractmethod
12281228

12291229
class Drawable():
12301230
__metaclass__ = ABCMeta
@@ -1256,15 +1256,21 @@ exception for classes that don't define the method.
12561256
Note that the exception is only raised when you actually
12571257
try to create an instance of a subclass lacking the method::
12581258

1259-
>>> s=Square()
1259+
>>> class Circle(Drawable):
1260+
... pass
1261+
...
1262+
>>> c=Circle()
12601263
Traceback (most recent call last):
12611264
File "<stdin>", line 1, in <module>
1262-
TypeError: Can't instantiate abstract class Square with abstract methods draw
1265+
TypeError: Can't instantiate abstract class Circle with abstract methods draw
12631266
>>>
12641267

12651268
Abstract data attributes can be declared using the
12661269
``@abstractproperty`` decorator::
12671270

1271+
from abc import abstractproperty
1272+
...
1273+
12681274
@abstractproperty
12691275
def readonly(self):
12701276
return self._x
@@ -1595,6 +1601,22 @@ Some smaller changes made to the core Python language are:
15951601
:func:`complex` constructor will now preserve the sign
15961602
of the zero. (Fixed by Mark T. Dickinson; :issue:`1507`.)
15971603

1604+
* Classes that inherit a :meth:`__hash__` method from a parent class
1605+
can set ``__hash__ = None`` to indicate that the class isn't
1606+
hashable. This will make ``hash(obj)`` raise a :exc:`TypeError`
1607+
and the class will not be indicated as implementing the
1608+
:class:`Hashable` ABC.
1609+
1610+
You should do this when you've defined a :meth:`__cmp__` or
1611+
:meth:`__eq__` method that compares objects by their value rather
1612+
than by identity. All objects have a default hash method that uses
1613+
``id(obj)`` as the hash value. There's no tidy way to remove the
1614+
:meth:`__hash__` method inherited from a parent class, so
1615+
assigning ``None`` was implemented as an override. At the
1616+
C level, extensions can set ``tp_hash`` to
1617+
:cfunc:`PyObject_HashNotImplemented`.
1618+
(Fixed by Nick Coghlan and Amaury Forgeot d'Arc; :issue:`2235`.)
1619+
15981620
* Changes to the :class:`Exception` interface
15991621
as dictated by :pep:`352` continue to be made. For 2.6,
16001622
the :attr:`message` attribute is being deprecated in favor of the
@@ -2501,14 +2523,14 @@ changes, or look through the Subversion logs for all the details.
25012523

25022524
(Contributed by Dwayne Bailey; :issue:`1581073`.)
25032525

2504-
* The :mod:`threading` module API is being changed in Python 3.0 to
2505-
use properties such as :attr:`daemon` instead of :meth:`setDaemon`
2506-
and :meth:`isDaemon` methods, and some methods have been renamed to
2507-
use underscores instead of camel-case; for example, the
2508-
:meth:`activeCount` method is renamed to :meth:`active_count`. The
2509-
2.6 version of the module supports the same properties and renamed
2510-
methods, but doesn't remove the old methods. (Carried out by
2511-
several people, most notably Benjamin Peterson.)
2526+
* The :mod:`threading` module API is being changed to use properties such as
2527+
:attr:`daemon` instead of :meth:`setDaemon` and :meth:`isDaemon` methods, and
2528+
some methods have been renamed to use underscores instead of camel-case; for
2529+
example, the :meth:`activeCount` method is renamed to :meth:`active_count`.
2530+
The 2.6 version of the module supports the same properties and renamed
2531+
methods, but doesn't remove the old methods. 3.0 also fully supports both
2532+
APIs, and a date for the deprecation of the old APIs has not been set yet.
2533+
(Carried out by several people, most notably Benjamin Peterson.)
25122534

25132535
The :mod:`threading` module's :class:`Thread` objects
25142536
gained an :attr:`ident` property that returns the thread's
@@ -3125,6 +3147,10 @@ Porting to Python 2.6
31253147
This section lists previously described changes and other bugfixes
31263148
that may require changes to your code:
31273149

3150+
* Classes that aren't supposed to be hashable should
3151+
set ``__hash__ = None`` in their definitions to indicate
3152+
the fact.
3153+
31283154
* The :meth:`__init__` method of :class:`collections.deque`
31293155
now clears any existing contents of the deque
31303156
before adding elements from the iterable. This change makes the
@@ -3147,6 +3173,10 @@ that may require changes to your code:
31473173
functions now default to absolute imports, not relative imports.
31483174
This will affect C extensions that import other modules.
31493175

3176+
* C API: extension data types that shouldn't be hashable
3177+
should define their ``tp_hash`` slot to
3178+
:cfunc:`PyObject_HashNotImplemented`.
3179+
31503180
* The :mod:`socket` module exception :exc:`socket.error` now inherits
31513181
from :exc:`IOError`. Previously it wasn't a subclass of
31523182
:exc:`StandardError` but now it is, through :exc:`IOError`.
@@ -3182,5 +3212,5 @@ Acknowledgements
31823212

31833213
The author would like to thank the following people for offering suggestions,
31843214
corrections and assistance with various drafts of this article:
3185-
Georg Brandl, Jim Jewett, Antoine Pitrou.
3215+
Georg Brandl, Steve Brown, Nick Coghlan, Jim Jewett, Antoine Pitrou.
31863216

0 commit comments

Comments
 (0)