4
4
5
5
.. XXX add trademark info for Apple, Microsoft, SourceForge.
6
6
7
- :Author: A.M. Kuchling
7
+ :Author: A.M. Kuchling (amk at amk.ca)
8
8
:Release: |release |
9
9
:Date: |today |
10
10
@@ -203,7 +203,7 @@ The Python documentation was written using LaTeX since the project
203
203
started around 1989. In the 1980s and early 1990s, most documentation
204
204
was printed out for later study, not viewed online. LaTeX was widely
205
205
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
207
207
learned.
208
208
209
209
Today LaTeX is still used for writing publications destined for
@@ -1224,7 +1224,7 @@ do it where it's absolutely necessary.
1224
1224
You can write your own ABCs by using ``abc.ABCMeta `` as the
1225
1225
metaclass in a class definition::
1226
1226
1227
- from abc import ABCMeta
1227
+ from abc import ABCMeta, abstractmethod
1228
1228
1229
1229
class Drawable():
1230
1230
__metaclass__ = ABCMeta
@@ -1256,15 +1256,21 @@ exception for classes that don't define the method.
1256
1256
Note that the exception is only raised when you actually
1257
1257
try to create an instance of a subclass lacking the method::
1258
1258
1259
- >>> s=Square()
1259
+ >>> class Circle(Drawable):
1260
+ ... pass
1261
+ ...
1262
+ >>> c=Circle()
1260
1263
Traceback (most recent call last):
1261
1264
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
1263
1266
>>>
1264
1267
1265
1268
Abstract data attributes can be declared using the
1266
1269
``@abstractproperty `` decorator::
1267
1270
1271
+ from abc import abstractproperty
1272
+ ...
1273
+
1268
1274
@abstractproperty
1269
1275
def readonly(self):
1270
1276
return self._x
@@ -1595,6 +1601,22 @@ Some smaller changes made to the core Python language are:
1595
1601
:func: `complex ` constructor will now preserve the sign
1596
1602
of the zero. (Fixed by Mark T. Dickinson; :issue: `1507 `.)
1597
1603
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
+
1598
1620
* Changes to the :class: `Exception ` interface
1599
1621
as dictated by :pep: `352 ` continue to be made. For 2.6,
1600
1622
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.
2501
2523
2502
2524
(Contributed by Dwayne Bailey; :issue: `1581073 `.)
2503
2525
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.)
2512
2534
2513
2535
The :mod: `threading ` module's :class: `Thread ` objects
2514
2536
gained an :attr: `ident ` property that returns the thread's
@@ -3125,6 +3147,10 @@ Porting to Python 2.6
3125
3147
This section lists previously described changes and other bugfixes
3126
3148
that may require changes to your code:
3127
3149
3150
+ * Classes that aren't supposed to be hashable should
3151
+ set ``__hash__ = None `` in their definitions to indicate
3152
+ the fact.
3153
+
3128
3154
* The :meth: `__init__ ` method of :class: `collections.deque `
3129
3155
now clears any existing contents of the deque
3130
3156
before adding elements from the iterable. This change makes the
@@ -3147,6 +3173,10 @@ that may require changes to your code:
3147
3173
functions now default to absolute imports, not relative imports.
3148
3174
This will affect C extensions that import other modules.
3149
3175
3176
+ * C API: extension data types that shouldn't be hashable
3177
+ should define their ``tp_hash `` slot to
3178
+ :cfunc: `PyObject_HashNotImplemented `.
3179
+
3150
3180
* The :mod: `socket ` module exception :exc: `socket.error ` now inherits
3151
3181
from :exc: `IOError `. Previously it wasn't a subclass of
3152
3182
:exc: `StandardError ` but now it is, through :exc: `IOError `.
@@ -3182,5 +3212,5 @@ Acknowledgements
3182
3212
3183
3213
The author would like to thank the following people for offering suggestions,
3184
3214
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.
3186
3216
0 commit comments