Kaydet (Commit) dcc1e117 authored tarafından Benjamin Peterson's avatar Benjamin Peterson

Merged revisions 66134,66136,66143,66154-66155,66190 via svnmerge from

svn+ssh://pythondev@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
........
üst a64072f9
...@@ -253,7 +253,7 @@ Available Classes ...@@ -253,7 +253,7 @@ Available Classes
.. class:: catch_warnings([\*, record=False, module=None]) .. 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 mutated. The manager returns an instance of :class:`WarningsRecorder`. The
*record* argument specifies whether warnings that would typically be *record* argument specifies whether warnings that would typically be
handled by :func:`showwarning` should instead be recorded by the handled by :func:`showwarning` should instead be recorded by the
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
.. XXX add trademark info for Apple, Microsoft, SourceForge. .. XXX add trademark info for Apple, Microsoft, SourceForge.
:Author: A.M. Kuchling :Author: A.M. Kuchling (amk at amk.ca)
:Release: |release| :Release: |release|
:Date: |today| :Date: |today|
...@@ -203,7 +203,7 @@ The Python documentation was written using LaTeX since the project ...@@ -203,7 +203,7 @@ The Python documentation was written using LaTeX since the project
started around 1989. In the 1980s and early 1990s, most documentation started around 1989. In the 1980s and early 1990s, most documentation
was printed out for later study, not viewed online. LaTeX was widely was printed out for later study, not viewed online. LaTeX was widely
used because it provided attractive printed output while remaining 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. learned.
Today LaTeX is still used for writing publications destined for Today LaTeX is still used for writing publications destined for
...@@ -1224,7 +1224,7 @@ do it where it's absolutely necessary. ...@@ -1224,7 +1224,7 @@ do it where it's absolutely necessary.
You can write your own ABCs by using ``abc.ABCMeta`` as the You can write your own ABCs by using ``abc.ABCMeta`` as the
metaclass in a class definition:: metaclass in a class definition::
from abc import ABCMeta from abc import ABCMeta, abstractmethod
class Drawable(): class Drawable():
__metaclass__ = ABCMeta __metaclass__ = ABCMeta
...@@ -1256,15 +1256,21 @@ exception for classes that don't define the method. ...@@ -1256,15 +1256,21 @@ exception for classes that don't define the method.
Note that the exception is only raised when you actually Note that the exception is only raised when you actually
try to create an instance of a subclass lacking the method:: try to create an instance of a subclass lacking the method::
>>> s=Square() >>> class Circle(Drawable):
... pass
...
>>> c=Circle()
Traceback (most recent call last): Traceback (most recent call last):
File "<stdin>", line 1, in <module> 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 Abstract data attributes can be declared using the
``@abstractproperty`` decorator:: ``@abstractproperty`` decorator::
from abc import abstractproperty
...
@abstractproperty @abstractproperty
def readonly(self): def readonly(self):
return self._x return self._x
...@@ -1595,6 +1601,22 @@ Some smaller changes made to the core Python language are: ...@@ -1595,6 +1601,22 @@ Some smaller changes made to the core Python language are:
:func:`complex` constructor will now preserve the sign :func:`complex` constructor will now preserve the sign
of the zero. (Fixed by Mark T. Dickinson; :issue:`1507`.) 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 * Changes to the :class:`Exception` interface
as dictated by :pep:`352` continue to be made. For 2.6, as dictated by :pep:`352` continue to be made. For 2.6,
the :attr:`message` attribute is being deprecated in favor of the 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,14 +2523,14 @@ changes, or look through the Subversion logs for all the details.
(Contributed by Dwayne Bailey; :issue:`1581073`.) (Contributed by Dwayne Bailey; :issue:`1581073`.)
* The :mod:`threading` module API is being changed in Python 3.0 to * The :mod:`threading` module API is being changed to use properties such as
use properties such as :attr:`daemon` instead of :meth:`setDaemon` :attr:`daemon` instead of :meth:`setDaemon` and :meth:`isDaemon` methods, and
and :meth:`isDaemon` methods, and some methods have been renamed to some methods have been renamed to use underscores instead of camel-case; for
use underscores instead of camel-case; for example, the example, the :meth:`activeCount` method is renamed to :meth:`active_count`.
:meth:`activeCount` method is renamed to :meth:`active_count`. The The 2.6 version of the module supports the same properties and renamed
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
methods, but doesn't remove the old methods. (Carried out by APIs, and a date for the deprecation of the old APIs has not been set yet.
several people, most notably Benjamin Peterson.) (Carried out by several people, most notably Benjamin Peterson.)
The :mod:`threading` module's :class:`Thread` objects The :mod:`threading` module's :class:`Thread` objects
gained an :attr:`ident` property that returns the thread's gained an :attr:`ident` property that returns the thread's
...@@ -3125,6 +3147,10 @@ Porting to Python 2.6 ...@@ -3125,6 +3147,10 @@ Porting to Python 2.6
This section lists previously described changes and other bugfixes This section lists previously described changes and other bugfixes
that may require changes to your code: 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` * The :meth:`__init__` method of :class:`collections.deque`
now clears any existing contents of the deque now clears any existing contents of the deque
before adding elements from the iterable. This change makes the before adding elements from the iterable. This change makes the
...@@ -3147,6 +3173,10 @@ that may require changes to your code: ...@@ -3147,6 +3173,10 @@ that may require changes to your code:
functions now default to absolute imports, not relative imports. functions now default to absolute imports, not relative imports.
This will affect C extensions that import other modules. 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 * The :mod:`socket` module exception :exc:`socket.error` now inherits
from :exc:`IOError`. Previously it wasn't a subclass of from :exc:`IOError`. Previously it wasn't a subclass of
:exc:`StandardError` but now it is, through :exc:`IOError`. :exc:`StandardError` but now it is, through :exc:`IOError`.
...@@ -3182,5 +3212,5 @@ Acknowledgements ...@@ -3182,5 +3212,5 @@ Acknowledgements
The author would like to thank the following people for offering suggestions, The author would like to thank the following people for offering suggestions,
corrections and assistance with various drafts of this article: 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.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment