Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 1 | **************************** |
| 2 | What's New In Python 3.4 |
| 3 | **************************** |
| 4 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 5 | :Author: R. David Murray <rdmurray@bitdance.com> (Editor) |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 6 | |
| 7 | .. Rules for maintenance: |
| 8 | |
Nick Coghlan | 03074fd | 2012-09-30 18:51:53 +0530 | [diff] [blame] | 9 | * Anyone can add text to this document, but the maintainer reserves the |
| 10 | right to rewrite any additions. In particular, for obscure or esoteric |
| 11 | features, the maintainer may reduce any addition to a simple reference to |
| 12 | the new documentation rather than explaining the feature inline. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 13 | |
Nick Coghlan | 03074fd | 2012-09-30 18:51:53 +0530 | [diff] [blame] | 14 | * While the maintainer will periodically go through Misc/NEWS |
| 15 | and add changes, it's best not to rely on this. We know from experience |
| 16 | that any changes that aren't in the What's New documentation around the |
| 17 | time of the original release will remain largely unknown to the community |
| 18 | for years, even if they're added later. We also know from experience that |
| 19 | other priorities can arise, and the maintainer will run out of time to do |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 20 | updates -- in such cases, end users will be much better served by partial |
Nick Coghlan | 03074fd | 2012-09-30 18:51:53 +0530 | [diff] [blame] | 21 | notifications that at least give a hint about new features to |
| 22 | investigate. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 23 | |
| 24 | * This is not a complete list of every single change; completeness |
Nick Coghlan | 03074fd | 2012-09-30 18:51:53 +0530 | [diff] [blame] | 25 | is the purpose of Misc/NEWS. The What's New should focus on changes that |
| 26 | are visible to Python *users* and that *require* a feature release (i.e. |
| 27 | most bug fixes should only be recorded in Misc/NEWS) |
| 28 | |
| 29 | * PEPs should not be marked Final until they have an entry in What's New. |
| 30 | A placeholder entry that is just a section header and a link to the PEP |
| 31 | (e.g ":pep:`397` has been implemented") is acceptable. If a PEP has been |
| 32 | implemented and noted in What's New, don't forget to mark it as Final! |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 33 | |
| 34 | * If you want to draw your new text to the attention of the |
| 35 | maintainer, add 'XXX' to the beginning of the paragraph or |
| 36 | section. |
| 37 | |
Nick Coghlan | 03074fd | 2012-09-30 18:51:53 +0530 | [diff] [blame] | 38 | * It's OK to add just a very brief note about a change. For |
| 39 | example: "The :ref:`~socket.transmogrify()` function was added to the |
| 40 | :mod:`socket` module." The maintainer will research the change and |
| 41 | write the necessary text (if appropriate). The advantage of doing this |
| 42 | is that even if no more descriptive text is ever added, readers will at |
| 43 | least have a notification that the new feature exists and a link to the |
| 44 | relevant documentation. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 45 | |
| 46 | * You can comment out your additions if you like, but it's not |
| 47 | necessary (especially when a final release is some months away). |
| 48 | |
| 49 | * Credit the author of a patch or bugfix. Just the name is |
| 50 | sufficient; the e-mail address isn't necessary. |
| 51 | |
| 52 | * It's helpful to add the bug/patch number as a comment: |
| 53 | |
Nick Coghlan | 03074fd | 2012-09-30 18:51:53 +0530 | [diff] [blame] | 54 | The :ref:`~socket.transmogrify()` function was added to the |
| 55 | :mod:`socket` module. (Contributed by P.Y. Developer in :issue:`12345`.) |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 56 | |
| 57 | This saves the maintainer the effort of going through the Mercurial log |
| 58 | when researching a change. |
| 59 | |
Nick Coghlan | 03074fd | 2012-09-30 18:51:53 +0530 | [diff] [blame] | 60 | * Cross referencing tip: :ref:`mod.attr` will display as ``mod.attr``, |
| 61 | while :ref:`~mod.attr` will display as ``attr``. |
| 62 | |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 63 | This article explains the new features in Python 3.4, compared to 3.3. |
Larry Hastings | 3101b70 | 2014-03-15 22:43:17 -0700 | [diff] [blame^] | 64 | Python 3.4 was released on March 16, 2014. For full details, see the |
Ezio Melotti | 25bbe5e | 2012-11-17 19:30:48 +0200 | [diff] [blame] | 65 | `changelog <http://docs.python.org/3.4/whatsnew/changelog.html>`_. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 66 | |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 67 | |
| 68 | .. seealso:: |
| 69 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 70 | :pep:`429` -- Python 3.4 Release Schedule |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 71 | |
| 72 | |
R David Murray | e608255 | 2014-01-03 16:15:45 -0500 | [diff] [blame] | 73 | |
R David Murray | e7cf678 | 2013-12-24 14:51:25 -0500 | [diff] [blame] | 74 | Summary -- Release Highlights |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 75 | ============================= |
| 76 | |
Kristjan Valur Jonsson | a1e8244 | 2013-03-26 13:56:14 +0000 | [diff] [blame] | 77 | .. This section singles out the most important changes in Python 3.4. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 78 | Brevity is key. |
| 79 | |
| 80 | New syntax features: |
| 81 | |
R David Murray | e0f7a78 | 2013-12-20 16:04:29 -0500 | [diff] [blame] | 82 | * No new syntax features were added in Python 3.4. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 83 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 84 | Other new features: |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 85 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 86 | * :ref:`pip should always be available <whatsnew-pep-453>` (:pep:`453`). |
| 87 | * :ref:`Newly created file descriptors are non-inheritable <whatsnew-pep-446>` |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 88 | (:pep:`446`). |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 89 | * command line option for :ref:`isolated mode <whatsnew-isolated-mode>` |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 90 | (:issue:`16499`). |
R David Murray | 8d85678 | 2013-12-23 10:28:57 -0500 | [diff] [blame] | 91 | * :ref:`improvements in the handling of codecs <codec-handling-improvements>` |
| 92 | that are not text encodings (multiple issues). |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 93 | * :ref:`A ModuleSpec Type <whatsnew-pep-451>` for the Import System |
R David Murray | e9b74d4 | 2013-12-22 21:05:04 -0500 | [diff] [blame] | 94 | (:pep:`451`). (Affects importer authors.) |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 95 | * The :mod:`marshal` format has been made :ref:`more compact and efficient |
| 96 | <whatsnew-marshal-3>` (:issue:`16475`). |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 97 | |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 98 | New library modules: |
| 99 | |
R David Murray | 9217dad | 2013-12-23 21:08:28 -0500 | [diff] [blame] | 100 | * :mod:`asyncio`: :ref:`New provisional API for asynchronous IO |
| 101 | <whatsnew-asyncio>` (:pep:`3156`). |
| 102 | * :mod:`ensurepip`: :ref:`Bootstrapping the pip installer <whatsnew-ensurepip>` |
| 103 | (:pep:`453`). |
| 104 | * :mod:`enum`: :ref:`Support for enumeration types <whatsnew-enum>` |
| 105 | (:pep:`435`). |
| 106 | * :mod:`pathlib`: :ref:`Object-oriented filesystem paths <whatsnew-pathlib>` |
| 107 | (:pep:`428`). |
R David Murray | f9976e7 | 2013-12-23 10:32:02 -0500 | [diff] [blame] | 108 | * :mod:`selectors`: :ref:`High-level and efficient I/O multiplexing |
| 109 | <whatsnew-selectors>`, built upon the :mod:`select` module primitives (part |
| 110 | of :pep:`3156`). |
R David Murray | 9217dad | 2013-12-23 21:08:28 -0500 | [diff] [blame] | 111 | * :mod:`statistics`: A basic :ref:`numerically stable statistics library |
| 112 | <whatsnew-statistics>` (:pep:`450`). |
| 113 | * :mod:`tracemalloc`: :ref:`Trace Python memory allocations |
| 114 | <whatsnew-tracemalloc>` (:pep:`454`). |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 115 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 116 | Significantly improved library modules: |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 117 | |
R David Murray | 0a10216 | 2013-12-20 15:00:54 -0500 | [diff] [blame] | 118 | * :ref:`Single-dispatch generic functions <whatsnew-singledispatch>` in |
R David Murray | 8d85678 | 2013-12-23 10:28:57 -0500 | [diff] [blame] | 119 | :mod:`functools` (:pep:`443`). |
| 120 | * New :mod:`pickle` :ref:`protocol 4 <whatsnew-protocol-4>` (:pep:`3154`). |
R David Murray | ac18622 | 2013-12-20 17:23:57 -0500 | [diff] [blame] | 121 | * :mod:`multiprocessing` now has :ref:`an option to avoid using os.fork |
| 122 | on Unix <whatsnew-multiprocessing-no-fork>` (:issue:`8713`). |
R David Murray | 6adb454 | 2013-12-20 13:10:43 -0500 | [diff] [blame] | 123 | * :mod:`email` has a new submodule, :mod:`~email.contentmanager`, and |
| 124 | a new :mod:`~email.message.Message` subclass |
R David Murray | 26b80cfd | 2013-12-20 17:26:52 -0500 | [diff] [blame] | 125 | (:class:`~email.contentmanager.EmailMessage`) that :ref:`simplify MIME |
R David Murray | 8d85678 | 2013-12-23 10:28:57 -0500 | [diff] [blame] | 126 | handling <whatsnew_email_contentmanager>` (:issue:`18891`). |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 127 | * The :mod:`inspect` and :mod:`pydoc` modules are now capable of |
| 128 | correct introspection of a much wider variety of callable objects, |
| 129 | which improves the output of the Python :func:`help` system. |
Nick Coghlan | 96bb437 | 2014-02-09 09:18:26 +1000 | [diff] [blame] | 130 | * The :mod:`ipaddress` module API has been declared stable |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 131 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 132 | Security improvements: |
| 133 | |
| 134 | * :ref:`Secure and interchangeable hash algorithm <whatsnew-pep-456>` |
| 135 | (:pep:`456`). |
| 136 | * :ref:`Make newly created file descriptors non-inheritable <whatsnew-pep-446>` |
| 137 | (:pep:`446`) to avoid leaking file descriptors to child processes. |
| 138 | * New command line option for :ref:`isolated mode <whatsnew-isolated-mode>`, |
| 139 | (:issue:`16499`). |
| 140 | * :mod:`multiprocessing` now has :ref:`an option to avoid using os.fork |
| 141 | on Unix <whatsnew-multiprocessing-no-fork>`. *spawn* and *forkserver* are |
| 142 | more secure because they avoid sharing data with child processes. |
| 143 | * :mod:`multiprocessing` child processes on Windows no longer inherit |
| 144 | all of the parent's inheritable handles, only the necessary ones. |
| 145 | * A new :func:`hashlib.pbkdf2_hmac` function provides |
| 146 | the `PKCS#5 password-based key derivation function 2 |
| 147 | <http://en.wikipedia.org/wiki/PBKDF2>`_. |
| 148 | * :ref:`TLSv1.1 and TLSv1.2 support <whatsnew-tls-11-12>` for :mod:`ssl`. |
| 149 | * :ref:`Retrieving certificates from the Windows system cert store support |
| 150 | <whatsnew34-win-cert-store>` for :mod:`ssl`. |
| 151 | * :ref:`Server-side SNI (Server Name Indication) support |
| 152 | <whatsnew34-sni>` for :mod:`ssl`. |
| 153 | * The :class:`ssl.SSLContext` class has a :ref:`lot of improvements |
| 154 | <whatsnew34-sslcontext>`. |
| 155 | * All modules in the standard library that support SSL now support server |
| 156 | certificate verification, including hostname matching |
| 157 | (:func:`ssl.match_hostname`) and CRLs (Certificate Revocation lists, see |
| 158 | :func:`ssl.SSLContext.load_verify_locations`). |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 159 | |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 160 | CPython implementation improvements: |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 161 | |
R David Murray | a93ca97 | 2013-12-22 14:10:21 -0500 | [diff] [blame] | 162 | * :ref:`Safe object finalization <whatsnew-pep-442>` (:pep:`442`). |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 163 | * Leveraging :pep:`442`, in most cases :ref:`module globals are no longer set |
| 164 | to None during finalization <whatsnew-pep-442>` (:issue:`18214`). |
R David Murray | a93ca97 | 2013-12-22 14:10:21 -0500 | [diff] [blame] | 165 | * :ref:`Configurable memory allocators <whatsnew-pep-445>` (:pep:`445`). |
R David Murray | a93ca97 | 2013-12-22 14:10:21 -0500 | [diff] [blame] | 166 | * :ref:`Argument Clinic <whatsnew-pep-436>` (:pep:`436`). |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 167 | |
R David Murray | 347f9c7 | 2013-12-23 21:30:06 -0500 | [diff] [blame] | 168 | Please read on for a comprehensive list of user-facing changes, including many |
| 169 | other smaller improvements, CPython optimizations, deprecations, and potential |
| 170 | porting issues. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 171 | |
Nick Coghlan | d0cf063 | 2013-11-11 22:11:55 +1000 | [diff] [blame] | 172 | |
R David Murray | e608255 | 2014-01-03 16:15:45 -0500 | [diff] [blame] | 173 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 174 | New Features |
| 175 | ============ |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 176 | |
R David Murray | 6879066 | 2013-12-23 11:17:51 -0500 | [diff] [blame] | 177 | .. _whatsnew-pep-453: |
| 178 | |
R David Murray | e7cf678 | 2013-12-24 14:51:25 -0500 | [diff] [blame] | 179 | PEP 453: Explicit Bootstrapping of PIP in Python Installations |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 180 | -------------------------------------------------------------- |
Nick Coghlan | d0cf063 | 2013-11-11 22:11:55 +1000 | [diff] [blame] | 181 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 182 | Bootstrapping pip By Default |
| 183 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 184 | |
Nick Coghlan | d0cf063 | 2013-11-11 22:11:55 +1000 | [diff] [blame] | 185 | The new :mod:`ensurepip` module (defined in :pep:`453`) provides a standard |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 186 | cross-platform mechanism to bootstrap the pip installer into Python |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 187 | installations and virtual environments. The version of ``pip`` included |
| 188 | with Python 3.4.0 is ``pip`` 1.5.4, and future 3.4.x maintenance releases |
| 189 | will update the bundled version to the latest version of ``pip`` that is |
| 190 | available at the time of creating the release candidate. |
Nick Coghlan | d0cf063 | 2013-11-11 22:11:55 +1000 | [diff] [blame] | 191 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 192 | By default, the commands ``pipX`` and ``pipX.Y`` will be installed on all |
| 193 | platforms (where X.Y stands for the version of the Python installation), |
| 194 | along with the ``pip`` Python package and its dependencies. On Windows and |
| 195 | in virtual environments on all platforms, the unversioned ``pip`` command |
| 196 | will also be installed. On other platforms, the system wide unversioned |
| 197 | ``pip`` command typically refers to the separately installed Python 2 |
| 198 | version. |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 199 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 200 | The :ref:`pyvenv <scripts-pyvenv>` command line utility and the :mod:`venv` |
| 201 | module make use of the :mod:`ensurepip` module to make ``pip`` readily |
| 202 | available in virtual environments. When using the command line utility, |
| 203 | ``pip`` is installed by default, while when using the :mod:`venv` module |
| 204 | :ref:`venv-api` installation of ``pip`` must be requested explicitly. |
Nick Coghlan | 7bc4b3b | 2013-11-23 11:59:40 +1000 | [diff] [blame] | 205 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 206 | For CPython :ref:`source builds on POSIX systems <building-python-on-unix>`, |
| 207 | the ``make install`` and ``make altinstall`` commands bootstrap ``pip`` by |
| 208 | default. This behaviour can be controlled through configure options, and |
| 209 | overridden through Makefile options. |
Nick Coghlan | 7bc4b3b | 2013-11-23 11:59:40 +1000 | [diff] [blame] | 210 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 211 | On Windows and Mac OS X, the CPython installers now default to installing |
| 212 | ``pip`` along with CPython itself (users may opt out of installing it |
| 213 | during the installation process). Window users will need to opt in to the |
| 214 | automatic ``PATH`` modifications to have ``pip`` available from the command |
| 215 | line by default, otherwise it can still be accessed through the Python |
| 216 | launcher for Windows as ``py -m pip``. |
Nick Coghlan | 7bc4b3b | 2013-11-23 11:59:40 +1000 | [diff] [blame] | 217 | |
R David Murray | 6879066 | 2013-12-23 11:17:51 -0500 | [diff] [blame] | 218 | As `discussed in the PEP`__, platform packagers may choose not to install |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 219 | these commands by default, as long as, when invoked, they provide clear and |
| 220 | simple directions on how to install them on that platform (usually using |
| 221 | the system package manager). |
R David Murray | 6879066 | 2013-12-23 11:17:51 -0500 | [diff] [blame] | 222 | |
| 223 | __ http://www.python.org/dev/peps/pep-0453/#recommendations-for-downstream-distributors |
| 224 | |
Nick Coghlan | d0cf063 | 2013-11-11 22:11:55 +1000 | [diff] [blame] | 225 | .. note:: |
| 226 | |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 227 | To avoid conflicts between parallel Python 2 and Python 3 installations, |
| 228 | only the versioned ``pip3`` and ``pip3.4`` commands are bootstrapped by |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 229 | default when ``ensurepip`` is invoked directly - the ``--default-pip`` |
| 230 | option is needed to also request the unversioned ``pip`` command. |
| 231 | ``pyvenv`` and the Windows installer ensure that the unqualified ``pip`` |
| 232 | command is made available in those environments, and ``pip`` can always be |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 233 | invoked via the ``-m`` switch rather than directly to avoid ambiguity on |
| 234 | systems with multiple Python installations. |
Nick Coghlan | d0cf063 | 2013-11-11 22:11:55 +1000 | [diff] [blame] | 235 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 236 | |
| 237 | Documentation Changes |
| 238 | ~~~~~~~~~~~~~~~~~~~~~ |
| 239 | |
| 240 | As part of this change, the :ref:`installing-index` and |
| 241 | :ref:`distributing-index` sections of the documentation have been |
| 242 | completely redesigned as short getting started and FAQ documents. Most |
| 243 | packaging documentation has now been moved out to the Python Packaging |
| 244 | Authority maintained `Python Packaging User Guide |
| 245 | <http://packaging.python.org>`__ and the documentation of the individual |
| 246 | projects. |
| 247 | |
| 248 | However, as this migration is currently still incomplete, the legacy |
| 249 | versions of those guides remaining available as :ref:`install-index` |
| 250 | and :ref:`distutils-index`. |
| 251 | |
Nick Coghlan | d0cf063 | 2013-11-11 22:11:55 +1000 | [diff] [blame] | 252 | .. seealso:: |
| 253 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 254 | :pep:`453` -- Explicit bootstrapping of pip in Python installations |
Nick Coghlan | d0cf063 | 2013-11-11 22:11:55 +1000 | [diff] [blame] | 255 | PEP written by Donald Stufft and Nick Coghlan, implemented by |
Nick Coghlan | 7bc4b3b | 2013-11-23 11:59:40 +1000 | [diff] [blame] | 256 | Donald Stufft, Nick Coghlan, Martin von Löwis and Ned Deily. |
Nick Coghlan | d0cf063 | 2013-11-11 22:11:55 +1000 | [diff] [blame] | 257 | |
| 258 | |
R David Murray | f9909c2 | 2013-12-20 14:50:12 -0500 | [diff] [blame] | 259 | .. _whatsnew-pep-446: |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 260 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 261 | PEP 446: Newly Created File Descriptors Are Non-Inheritable |
| 262 | ----------------------------------------------------------- |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 263 | |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 264 | :pep:`446` makes newly created file descriptors :ref:`non-inheritable |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 265 | <fd_inheritance>`. In general, this is the behavior an application will |
| 266 | want: when launching a new process, having currently open files also |
| 267 | open in the new process can lead to all sorts of hard to find bugs, |
| 268 | and potentially to security issues. |
| 269 | |
| 270 | However, there are occasions when inheritance is desired. To support |
| 271 | these cases, the following new functions and methods are available: |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 272 | |
| 273 | * :func:`os.get_inheritable`, :func:`os.set_inheritable` |
| 274 | * :func:`os.get_handle_inheritable`, :func:`os.set_handle_inheritable` |
| 275 | * :meth:`socket.socket.get_inheritable`, :meth:`socket.socket.set_inheritable` |
| 276 | |
Antoine Pitrou | 796564c | 2013-07-30 19:59:21 +0200 | [diff] [blame] | 277 | .. seealso:: |
| 278 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 279 | :pep:`446` -- Make newly created file descriptors non-inheritable |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 280 | PEP written and implemented by Victor Stinner. |
Antoine Pitrou | 796564c | 2013-07-30 19:59:21 +0200 | [diff] [blame] | 281 | |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 282 | |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 283 | .. _codec-handling-improvements: |
| 284 | |
R David Murray | e7cf678 | 2013-12-24 14:51:25 -0500 | [diff] [blame] | 285 | Improvements to Codec Handling |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 286 | ------------------------------ |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 287 | |
| 288 | Since it was first introduced, the :mod:`codecs` module has always been |
| 289 | intended to operate as a type-neutral dynamic encoding and decoding |
| 290 | system. However, its close coupling with the Python text model, especially |
| 291 | the type restricted convenience methods on the builtin :class:`str`, |
| 292 | :class:`bytes` and :class:`bytearray` types, has historically obscured that |
| 293 | fact. |
| 294 | |
| 295 | As a key step in clarifying the situation, the :meth:`codecs.encode` and |
| 296 | :meth:`codecs.decode` convenience functions are now properly documented in |
| 297 | Python 2.7, 3.3 and 3.4. These functions have existed in the :mod:`codecs` |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 298 | module (and have been covered by the regression test suite) since Python 2.4, |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 299 | but were previously only discoverable through runtime introspection. |
| 300 | |
| 301 | Unlike the convenience methods on :class:`str`, :class:`bytes` and |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 302 | :class:`bytearray`, the :mod:`codecs` convenience functions support arbitrary |
| 303 | codecs in both Python 2 and Python 3, rather than being limited to Unicode text |
| 304 | encodings (in Python 3) or ``basestring`` <-> ``basestring`` conversions (in |
| 305 | Python 2). |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 306 | |
Nick Coghlan | 8afc8f6 | 2013-11-22 23:00:22 +1000 | [diff] [blame] | 307 | In Python 3.4, the interpreter is able to identify the known non-text |
| 308 | encodings provided in the standard library and direct users towards these |
| 309 | general purpose convenience functions when appropriate:: |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 310 | |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 311 | >>> b"abcdef".decode("hex") |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 312 | Traceback (most recent call last): |
| 313 | File "<stdin>", line 1, in <module> |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 314 | LookupError: 'hex' is not a text encoding; use codecs.decode() to handle arbitrary codecs |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 315 | |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 316 | >>> "hello".encode("rot13") |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 317 | Traceback (most recent call last): |
| 318 | File "<stdin>", line 1, in <module> |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 319 | LookupError: 'rot13' is not a text encoding; use codecs.encode() to handle arbitrary codecs |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 320 | |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 321 | >>> open("foo.txt", encoding="hex") |
| 322 | Traceback (most recent call last): |
| 323 | File "<stdin>", line 1, in <module> |
| 324 | LookupError: 'hex' is not a text encoding; use codecs.open() to handle arbitrary codecs |
| 325 | |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 326 | In a related change, whenever it is feasible without breaking backwards |
| 327 | compatibility, exceptions raised during encoding and decoding operations |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 328 | are wrapped in a chained exception of the same type that mentions the |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 329 | name of the codec responsible for producing the error:: |
| 330 | |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 331 | >>> import codecs |
| 332 | |
| 333 | >>> codecs.decode(b"abcdefgh", "hex") |
Nick Coghlan | 77b286b | 2014-01-27 00:53:38 +1000 | [diff] [blame] | 334 | Traceback (most recent call last): |
| 335 | File "/usr/lib/python3.4/encodings/hex_codec.py", line 20, in hex_decode |
| 336 | return (binascii.a2b_hex(input), len(input)) |
Nick Coghlan | 8afc8f6 | 2013-11-22 23:00:22 +1000 | [diff] [blame] | 337 | binascii.Error: Non-hexadecimal digit found |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 338 | |
| 339 | The above exception was the direct cause of the following exception: |
| 340 | |
| 341 | Traceback (most recent call last): |
| 342 | File "<stdin>", line 1, in <module> |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 343 | binascii.Error: decoding with 'hex' codec failed (Error: Non-hexadecimal digit found) |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 344 | |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 345 | >>> codecs.encode("hello", "bz2") |
Nick Coghlan | 77b286b | 2014-01-27 00:53:38 +1000 | [diff] [blame] | 346 | Traceback (most recent call last): |
| 347 | File "/usr/lib/python3.4/encodings/bz2_codec.py", line 17, in bz2_encode |
| 348 | return (bz2.compress(input), len(input)) |
| 349 | File "/usr/lib/python3.4/bz2.py", line 498, in compress |
| 350 | return comp.compress(data) + comp.flush() |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 351 | TypeError: 'str' does not support the buffer interface |
| 352 | |
| 353 | The above exception was the direct cause of the following exception: |
| 354 | |
| 355 | Traceback (most recent call last): |
| 356 | File "<stdin>", line 1, in <module> |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 357 | TypeError: encoding with 'bz2' codec failed (TypeError: 'str' does not support the buffer interface) |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 358 | |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 359 | Finally, as the examples above show, these improvements have permitted |
| 360 | the restoration of the convenience aliases for the non-Unicode codecs that |
| 361 | were themselves restored in Python 3.2. This means that encoding binary data |
| 362 | to and from its hexadecimal representation (for example) can now be written |
| 363 | as:: |
| 364 | |
| 365 | >>> from codecs import encode, decode |
| 366 | >>> encode(b"hello", "hex") |
| 367 | b'68656c6c6f' |
| 368 | >>> decode(b"68656c6c6f", "hex") |
| 369 | b'hello' |
| 370 | |
| 371 | The binary and text transforms provided in the standard library are detailed |
| 372 | in :ref:`binary-transforms` and :ref:`text-transforms`. |
| 373 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 374 | (Contributed by Nick Coghlan in :issue:`7475`, :issue:`17827`, |
Nick Coghlan | 9c1aed8 | 2013-11-23 11:13:36 +1000 | [diff] [blame] | 375 | :issue:`17828` and :issue:`19619`) |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 376 | |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 377 | |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 378 | .. _whatsnew-pep-451: |
Eric Snow | b523f84 | 2013-11-22 09:05:39 -0700 | [diff] [blame] | 379 | |
| 380 | PEP 451: A ModuleSpec Type for the Import System |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 381 | ------------------------------------------------ |
Eric Snow | b523f84 | 2013-11-22 09:05:39 -0700 | [diff] [blame] | 382 | |
R David Murray | f85b2a8 | 2013-12-22 21:06:13 -0500 | [diff] [blame] | 383 | :pep:`451` provides an encapsulation of the information about a module that the |
| 384 | import machinery will use to load it (that is, a module specification). This |
| 385 | helps simplify both the import implementation and several import-related APIs. |
| 386 | The change is also a stepping stone for `several future import-related |
| 387 | improvements`__. |
Eric Snow | b523f84 | 2013-11-22 09:05:39 -0700 | [diff] [blame] | 388 | |
R David Murray | e9b74d4 | 2013-12-22 21:05:04 -0500 | [diff] [blame] | 389 | __ https://mail.python.org/pipermail/python-dev/2013-November/130111.html |
Eric Snow | b523f84 | 2013-11-22 09:05:39 -0700 | [diff] [blame] | 390 | |
| 391 | The public-facing changes from the PEP are entirely backward-compatible. |
R David Murray | f85b2a8 | 2013-12-22 21:06:13 -0500 | [diff] [blame] | 392 | Furthermore, they should be transparent to everyone but importer authors. Key |
| 393 | finder and loader methods have been deprecated, but they will continue working. |
| 394 | New importers should use the new methods described in the PEP. Existing |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 395 | importers should be updated to implement the new methods. See the |
| 396 | :ref:`deprecated-3.4` section for a list of methods that should be replaced and |
| 397 | their replacements. |
Eric Snow | b523f84 | 2013-11-22 09:05:39 -0700 | [diff] [blame] | 398 | |
Nick Coghlan | 8b097b4 | 2013-11-13 23:49:21 +1000 | [diff] [blame] | 399 | |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 400 | Other Language Changes |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 401 | ---------------------- |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 402 | |
| 403 | Some smaller changes made to the core Python language are: |
| 404 | |
Ezio Melotti | 34808e2 | 2013-10-12 16:36:13 +0300 | [diff] [blame] | 405 | * Unicode database updated to UCD version 6.3. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 406 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 407 | * :func:`min` and :func:`max` now accept a *default* keyword-only argument that |
| 408 | can be used to specify the value they return if the iterable they are |
| 409 | evaluating has no elements. (Contributed by Julian Berman in |
| 410 | :issue:`18111`.) |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 411 | |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 412 | * Module objects are now :mod:`weakref`'able. |
| 413 | |
Nick Coghlan | 0acceb7 | 2013-10-20 13:22:21 +1000 | [diff] [blame] | 414 | * Module ``__file__`` attributes (and related values) should now always |
| 415 | contain absolute paths by default, with the sole exception of |
| 416 | ``__main__.__file__`` when a script has been executed directly using |
| 417 | a relative path (Contributed by Brett Cannon in :issue:`18416`). |
| 418 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 419 | * All the UTF-\* codecs (except UTF-7) now reject surrogates during both |
Serhiy Storchaka | 58cf607 | 2013-11-19 11:32:41 +0200 | [diff] [blame] | 420 | encoding and decoding unless the ``surrogatepass`` error handler is used, |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 421 | with the exception of the UTF-16 decoder (which accepts valid surrogate pairs) |
| 422 | and the UTF-16 encoder (which produces them while encoding non-BMP characters). |
Serhiy Storchaka | 58cf607 | 2013-11-19 11:32:41 +0200 | [diff] [blame] | 423 | Contributed by Victor Stinner, Kang-Hao (Kenny) Lu and Serhiy Storchaka in |
| 424 | :issue:`12892`. |
| 425 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 426 | * New German EBCDIC :ref:`codec <standard-encodings>` ``cp273``. (Contributed |
| 427 | by Michael Bierenfeld and Andrew Kuchling in :issue:`1097797`.) |
R David Murray | c4c7b1c | 2014-03-07 21:00:34 -0500 | [diff] [blame] | 428 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 429 | * New Ukrainian :ref:`codec <standard-encodings>` ``cp1125``. (Contributed by |
| 430 | Serhiy Storchaka in :issue:`19668`.) |
| 431 | |
| 432 | * :class:`bytes`.join() and :class:`bytearray`.join() now accept arbitrary |
| 433 | buffer objects as arguments. (Contributed by Antoine Pitrou in |
| 434 | :issue:`15958`.) |
| 435 | |
| 436 | * The :class:`int` constructor now accepts any object that has an ``__index__`` |
| 437 | method for its *base* argument. (Contributed by Mark Dickinson in |
| 438 | :issue:`16772`.) |
| 439 | |
| 440 | * Frame objects now have a :func:`~frame.clear` method that clears all |
| 441 | references to local variables from the frame. (Contributed by Antoine Pitrou |
| 442 | in :issue:`17934`.) |
| 443 | |
| 444 | * :class:`memoryview` is now registered as a :class:`Sequence <collections.abc>`, |
| 445 | and supports the :func:`reversed` builtin. (Contributed by Nick Coghlan |
| 446 | and Claudiu Popa in :issue:`18690` and :issue:`19078`.) |
| 447 | |
| 448 | * Signatures reported by :func:`help` have been modified and improved in |
| 449 | several cases as a result of the introduction of Argument Clinic and other |
| 450 | changes to the :mod:`inspect` and :mod:`pydoc` modules. |
| 451 | |
| 452 | * :meth:`~object.__length_hint__` is now part of the formal language |
| 453 | specification (see :pep:`424`). (Contributed by Armin Ronacher in |
| 454 | :issue:`16148`.) |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 455 | |
R David Murray | e608255 | 2014-01-03 16:15:45 -0500 | [diff] [blame] | 456 | |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 457 | New Modules |
| 458 | =========== |
| 459 | |
Nick Coghlan | 0acceb7 | 2013-10-20 13:22:21 +1000 | [diff] [blame] | 460 | |
R David Murray | 9217dad | 2013-12-23 21:08:28 -0500 | [diff] [blame] | 461 | .. _whatsnew-asyncio: |
| 462 | |
Nick Coghlan | 0acceb7 | 2013-10-20 13:22:21 +1000 | [diff] [blame] | 463 | asyncio |
| 464 | ------- |
| 465 | |
| 466 | The new :mod:`asyncio` module (defined in :pep:`3156`) provides a standard |
| 467 | pluggable event loop model for Python, providing solid asynchronous IO |
| 468 | support in the standard library, and making it easier for other event loop |
| 469 | implementations to interoperate with the standard library and each other. |
| 470 | |
| 471 | For Python 3.4, this module is considered a :term:`provisional API`. |
| 472 | |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 473 | .. seealso:: |
| 474 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 475 | :pep:`3156` -- Asynchronous IO Support Rebooted: the "asyncio" Module |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 476 | PEP written and implementation led by Guido van Rossum. |
| 477 | |
R David Murray | 6879066 | 2013-12-23 11:17:51 -0500 | [diff] [blame] | 478 | |
R David Murray | 9217dad | 2013-12-23 21:08:28 -0500 | [diff] [blame] | 479 | .. _whatsnew-ensurepip: |
R David Murray | 6879066 | 2013-12-23 11:17:51 -0500 | [diff] [blame] | 480 | |
| 481 | ensurepip |
| 482 | --------- |
| 483 | |
| 484 | The new :mod:`ensurepip` module is the primary infrastructure for the |
| 485 | :pep:`453` implementation. In the normal course of events end users will not |
| 486 | need to interact with this module, but it can be used to manually bootstrap |
| 487 | ``pip`` if the automated bootstrapping into an installation or virtual |
| 488 | environment was declined. |
| 489 | |
| 490 | :mod:`ensurepip` includes a bundled copy of ``pip``, up-to-date as of the first |
| 491 | release candidate of the release of CPython with which it ships (this applies |
| 492 | to both maintenance releases and feature releases). ``ensurepip`` does not |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 493 | access the internet. If the installation has Internet access, after |
| 494 | ``ensurepip`` is run the bundled ``pip`` can be used to upgrade ``pip`` to a |
| 495 | more recent release than the bundled one. (Note that such an upgraded version |
| 496 | of ``pip`` is considered to be a separately installed package and will not be |
| 497 | removed if Python is uninstalled.) |
R David Murray | 6879066 | 2013-12-23 11:17:51 -0500 | [diff] [blame] | 498 | |
| 499 | The module is named *ensure*\ pip because if called when ``pip`` is already |
| 500 | installed, it does nothing. It also has an ``--upgrade`` option that will |
| 501 | cause it to install the bundled copy of ``pip`` if the existing installed |
| 502 | version of ``pip`` is older than the bundled copy. |
| 503 | |
| 504 | |
R David Murray | 9217dad | 2013-12-23 21:08:28 -0500 | [diff] [blame] | 505 | .. _whatsnew-enum: |
| 506 | |
Nick Coghlan | 0acceb7 | 2013-10-20 13:22:21 +1000 | [diff] [blame] | 507 | enum |
| 508 | ---- |
| 509 | |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 510 | The new :mod:`enum` module (defined in :pep:`435`) provides a standard |
| 511 | implementation of enumeration types, allowing other modules (such as |
| 512 | :mod:`socket`) to provide more informative error messages and better |
| 513 | debugging support by replacing opaque integer constants with backwards |
| 514 | compatible enumeration values. |
| 515 | |
| 516 | .. seealso:: |
| 517 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 518 | :pep:`435` -- Adding an Enum type to the Python standard library |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 519 | PEP written by Barry Warsaw, Eli Bendersky and Ethan Furman, |
| 520 | implemented by Ethan Furman. |
Nick Coghlan | 0acceb7 | 2013-10-20 13:22:21 +1000 | [diff] [blame] | 521 | |
| 522 | |
R David Murray | 9217dad | 2013-12-23 21:08:28 -0500 | [diff] [blame] | 523 | .. _whatsnew-pathlib: |
| 524 | |
Antoine Pitrou | 31119e4 | 2013-11-22 17:38:12 +0100 | [diff] [blame] | 525 | pathlib |
| 526 | ------- |
| 527 | |
| 528 | The new :mod:`pathlib` module offers classes representing filesystem paths |
| 529 | with semantics appropriate for different operating systems. Path classes are |
| 530 | divided between *pure paths*, which provide purely computational operations |
| 531 | without I/O, and *concrete paths*, which inherit from pure paths but also |
| 532 | provide I/O operations. |
| 533 | |
| 534 | For Python 3.4, this module is considered a :term:`provisional API`. |
| 535 | |
| 536 | .. seealso:: |
| 537 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 538 | :pep:`428` -- The pathlib module -- object-oriented filesystem paths |
Antoine Pitrou | 31119e4 | 2013-11-22 17:38:12 +0100 | [diff] [blame] | 539 | PEP written and implemented by Antoine Pitrou. |
| 540 | |
| 541 | |
R David Murray | f9976e7 | 2013-12-23 10:32:02 -0500 | [diff] [blame] | 542 | .. _whatsnew-selectors: |
| 543 | |
Charles-François Natali | 243d8d8 | 2013-09-04 19:02:49 +0200 | [diff] [blame] | 544 | selectors |
| 545 | --------- |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 546 | |
Nick Coghlan | 0acceb7 | 2013-10-20 13:22:21 +1000 | [diff] [blame] | 547 | The new :mod:`selectors` module (created as part of implementing :pep:`3156`) |
| 548 | allows high-level and efficient I/O multiplexing, built upon the |
| 549 | :mod:`select` module primitives. |
| 550 | |
| 551 | |
R David Murray | 9217dad | 2013-12-23 21:08:28 -0500 | [diff] [blame] | 552 | .. _whatsnew-statistics: |
| 553 | |
Nick Coghlan | 0acceb7 | 2013-10-20 13:22:21 +1000 | [diff] [blame] | 554 | statistics |
| 555 | ---------- |
| 556 | |
| 557 | The new :mod:`statistics` module (defined in :pep:`450`) offers some core |
| 558 | statistics functionality directly in the standard library. This module |
| 559 | supports calculation of the mean, median, mode, variance and standard |
| 560 | deviation of a data series. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 561 | |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 562 | .. seealso:: |
| 563 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 564 | :pep:`450` -- Adding A Statistics Module To The Standard Library |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 565 | PEP written and implemented by Steven D'Aprano |
| 566 | |
R David Murray | 9217dad | 2013-12-23 21:08:28 -0500 | [diff] [blame] | 567 | .. _whatsnew-tracemalloc: |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 568 | |
R David Murray | 8b2d682 | 2013-12-31 15:06:05 -0500 | [diff] [blame] | 569 | |
Victor Stinner | d2736af | 2013-11-25 09:40:27 +0100 | [diff] [blame] | 570 | tracemalloc |
| 571 | ----------- |
| 572 | |
| 573 | The new :mod:`tracemalloc` module (defined in :pep:`454`) is a debug tool to |
| 574 | trace memory blocks allocated by Python. It provides the following information: |
| 575 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 576 | * Trace where an object was allocated |
Victor Stinner | d2736af | 2013-11-25 09:40:27 +0100 | [diff] [blame] | 577 | * Statistics on allocated memory blocks per filename and per line number: |
| 578 | total size, number and average size of allocated memory blocks |
| 579 | * Compute the differences between two snapshots to detect memory leaks |
| 580 | |
| 581 | .. seealso:: |
| 582 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 583 | :pep:`454` -- Add a new tracemalloc module to trace Python memory allocations |
Victor Stinner | d2736af | 2013-11-25 09:40:27 +0100 | [diff] [blame] | 584 | PEP written and implemented by Victor Stinner |
| 585 | |
| 586 | |
R David Murray | e608255 | 2014-01-03 16:15:45 -0500 | [diff] [blame] | 587 | |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 588 | Improved Modules |
| 589 | ================ |
| 590 | |
R David Murray | 6e39015 | 2013-12-24 22:28:04 -0500 | [diff] [blame] | 591 | |
R David Murray | 3edcc78 | 2013-12-24 16:13:32 -0500 | [diff] [blame] | 592 | abc |
| 593 | --- |
| 594 | |
| 595 | New function :func:`abc.get_cache_token` can be used to know when to invalidate |
| 596 | caches that are affected by changes in the object graph. (Contributed |
| 597 | by Łukasz Langa in :issue:`16832`.) |
R David Murray | 72420ff | 2013-12-24 10:46:44 -0500 | [diff] [blame] | 598 | |
R David Murray | 2691ee6 | 2013-12-28 23:15:12 -0500 | [diff] [blame] | 599 | New class :class:`~abc.ABC` has :class:`~abc.ABCMeta` as its meta class. |
| 600 | Using ``ABC`` as a base class has essentially the same effect as specifying |
| 601 | ``metaclass=abc.ABCMeta``, but is simpler to type and easier to read. |
| 602 | (Contributed by Bruno Dupuis in :issue:`16049`.) |
| 603 | |
| 604 | |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 605 | aifc |
| 606 | ---- |
| 607 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 608 | The :meth:`~aifc.aifc.getparams` method now returns a namedtuple rather than a |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 609 | plain tuple. (Contributed by Claudiu Popa in :issue:`17818`.) |
| 610 | |
R David Murray | d592bb2 | 2013-12-31 13:45:38 -0500 | [diff] [blame] | 611 | :func:`aifc.open` now supports the context manager protocol: when used in a |
| 612 | :keyword:`with` block, the :meth:`~aifc.aifc.close` method of the returned |
| 613 | object will be called automatically at the end of the block. (Contributed by |
| 614 | Serhiy Storchacha in :issue:`16486`.) |
| 615 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 616 | The :meth:`~aifc.aifc.writeframesraw` and :meth:`~aifc.aifc.writeframes` |
| 617 | methods now accept any :term:`bytes-like object`. (Contributed by Serhiy |
| 618 | Storchaka in :issue:`8311`.) |
| 619 | |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 620 | |
R David Murray | fced3ec | 2013-12-31 11:18:01 -0500 | [diff] [blame] | 621 | argparse |
| 622 | -------- |
| 623 | |
| 624 | The :class:`~argparse.FileType` class now accepts *encoding* and |
| 625 | *errors* arguments, which are passed through to :func:`open`. (Contributed |
| 626 | by Lucas Maystre in :issue:`11175`.) |
| 627 | |
| 628 | |
Serhiy Storchaka | eaea5e9 | 2013-10-19 21:10:46 +0300 | [diff] [blame] | 629 | audioop |
| 630 | ------- |
| 631 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 632 | :mod:`audioop` now supports 24-bit samples. (Contributed by Serhiy Storchaka |
| 633 | in :issue:`12866`.) |
Serhiy Storchaka | eaea5e9 | 2013-10-19 21:10:46 +0300 | [diff] [blame] | 634 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 635 | New :func:`~audioop.byteswap` function converts big-endian samples to |
| 636 | little-endian and vice versa (Contributed by Serhiy Storchaka in |
| 637 | :issue:`19641`). |
| 638 | |
| 639 | All :mod:`audioop` functions now accept any :term:`bytes-like object`. Strings |
| 640 | are not accepted: they didn't work before, now they raise an error right away. |
| 641 | (Contributed by Serhiy Storchaka in :issue:`16685`.) |
Serhiy Storchaka | 3062c9a | 2013-11-23 22:26:01 +0200 | [diff] [blame] | 642 | |
Serhiy Storchaka | eaea5e9 | 2013-10-19 21:10:46 +0300 | [diff] [blame] | 643 | |
Nick Coghlan | d4fdbcc | 2013-11-14 00:24:31 +1000 | [diff] [blame] | 644 | base64 |
| 645 | ------ |
| 646 | |
| 647 | The encoding and decoding functions in :mod:`base64` now accept any |
| 648 | :term:`bytes-like object` in cases where it previously required a |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 649 | :class:`bytes` or :class:`bytearray` instance. (Contributed by Nick Coghlan in |
| 650 | :issue:`17839`.) |
| 651 | |
| 652 | New functions :func:`~base64.a85encode`, :func:`~base64.a85decode`, |
| 653 | :func:`~base64.b85encode`, and :func:`~base64.b85decode` provide the ability to |
| 654 | encode and decode binary data from and to ``Ascii85`` and the git/mercurial |
| 655 | ``Base85`` formats, respectively. The ``a85`` functions have options that can |
| 656 | be used to make them compatible with the variants of the ``Ascii85`` encoding, |
| 657 | including the Adobe variant. (Contributed by Martin Morrison, the Mercurial |
| 658 | project, Serhiy Storchaka, and Antoine Pitrou in :issue:`17618`.) |
| 659 | |
| 660 | |
| 661 | collections |
| 662 | ----------- |
| 663 | |
| 664 | The :meth:`.ChainMap.new_child` method now accepts an *m* argument specifying |
| 665 | the child map to add to the chain. This allows an existing mapping and/or a |
| 666 | custom mapping type to be used for the child. (Contributed by Vinay Sajip in |
| 667 | :issue:`16613`.) |
Nick Coghlan | d4fdbcc | 2013-11-14 00:24:31 +1000 | [diff] [blame] | 668 | |
| 669 | |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 670 | colorsys |
| 671 | -------- |
| 672 | |
| 673 | The number of digits in the coefficients for the RGB --- YIQ conversions have |
| 674 | been expanded so that they match the FCC NTSC versions. The change in |
| 675 | results should be less than 1% and may better match results found elsewhere. |
R David Murray | 45e732d | 2014-02-03 01:33:39 -0500 | [diff] [blame] | 676 | (Contributed by Brian Landers and Serhiy Storchaka in :issue:`14323`.) |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 677 | |
R David Murray | 8e37d5d | 2013-04-13 14:49:48 -0400 | [diff] [blame] | 678 | |
Nick Coghlan | b4534ae | 2013-10-13 23:23:08 +1000 | [diff] [blame] | 679 | contextlib |
| 680 | ---------- |
| 681 | |
Nick Coghlan | 240f86d | 2013-10-17 23:40:57 +1000 | [diff] [blame] | 682 | The new :class:`contextlib.suppress` context manager helps to clarify the |
| 683 | intent of code that deliberately suppresses exceptions from a single |
| 684 | statement. (Contributed by Raymond Hettinger in :issue:`15806` and |
| 685 | Zero Piraeus in :issue:`19266`) |
| 686 | |
Victor Stinner | 6633c39 | 2013-10-21 13:27:11 +0200 | [diff] [blame] | 687 | The new :func:`contextlib.redirect_stdout` context manager makes it easier |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 688 | for utility scripts to handle inflexible APIs that write their output to |
| 689 | :data:`sys.stdout` and don't provide any options to redirect it. Using the |
| 690 | context manager, the :data:`sys.stdout` output can be redirected to any |
| 691 | other stream or, in conjunction with :class:`io.StringIO`, to a string. |
| 692 | The latter can be especially useful, for example, to capture output |
| 693 | from a function that was written to implement a command line interface. |
| 694 | It is recommended only for utility scripts because it affects the |
| 695 | global state of :data:`sys.stdout`. (Contributed by Raymond Hettinger |
| 696 | in :issue:`15805`) |
Nick Coghlan | 0acceb7 | 2013-10-20 13:22:21 +1000 | [diff] [blame] | 697 | |
| 698 | The :mod:`contextlib` documentation has also been updated to include a |
| 699 | :ref:`discussion <single-use-reusable-and-reentrant-cms>` of the |
| 700 | differences between single use, reusable and reentrant context managers. |
Nick Coghlan | b4534ae | 2013-10-13 23:23:08 +1000 | [diff] [blame] | 701 | |
| 702 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 703 | dbm |
| 704 | --- |
| 705 | |
| 706 | :func:`dbm.open` objects now support the context management protocol. When |
| 707 | used in a :keyword:`with` statement, the ``close`` method of the database |
| 708 | object will be called automatically at the end of the block. (Contributed by |
| 709 | Claudiu Popa and Nick Coghlan in :issue:`19282`.) |
| 710 | |
| 711 | |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 712 | dis |
| 713 | --- |
| 714 | |
R David Murray | 0bce6e7 | 2014-01-07 14:30:17 -0500 | [diff] [blame] | 715 | Functions :func:`~dis.show_code`, :func:`~dis.dis`, :func:`~dis.distb`, and |
| 716 | :func:`~dis.disassemble` now accept a keyword-only *file* argument that |
| 717 | controls where they write their output. |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 718 | |
R David Murray | 0bce6e7 | 2014-01-07 14:30:17 -0500 | [diff] [blame] | 719 | The :mod:`dis` module is now built around an :class:`~dis.Instruction` class |
| 720 | that provides object oriented access to the details of each individual bytecode |
| 721 | operation. |
| 722 | |
| 723 | A new method, :func:`~dis.get_instructions`, provides an iterator that emits |
| 724 | the Instruction stream for a given piece of Python code. Thus it is now |
| 725 | possible to write a program that inspects and manipulates a bytecode |
| 726 | object in ways different from those provided by the :mod:`~dis` module |
| 727 | itself. For example:: |
| 728 | |
| 729 | >>> import dis |
| 730 | >>> for instr in dis.get_instructions(lambda x: x + 1): |
| 731 | ... print(instr.opname) |
| 732 | LOAD_FAST |
| 733 | LOAD_CONST |
| 734 | BINARY_ADD |
| 735 | RETURN_VALUE |
| 736 | |
| 737 | The various display tools in the :mod:`dis` module have been rewritten to use |
| 738 | these new components. |
| 739 | |
| 740 | In addition, a new application-friendly class :class:`~dis.Bytecode` provides |
| 741 | an object-oriented API for inspecting bytecode in both in human-readable form |
| 742 | and for iterating over instructions. The :class:`~dis.Bytecode` constructor |
| 743 | takes the same arguments that :func:`~dis.get_instruction` does (plus an |
| 744 | optional *current_offset*), and the resulting object can be iterated to produce |
| 745 | :class:`~dis.Instruction` objects. But it also has a :mod:`~dis.Bytecode.dis` |
| 746 | method, equivalent to calling :mod:`~dis.dis` on the constructor argument, but |
| 747 | returned as a multi-line string:: |
| 748 | |
| 749 | >>> bytecode = dis.Bytecode(lambda x: x +1, current_offset=3) |
| 750 | >>> for instr in bytecode: |
| 751 | ... print('{} ({})'.format(instr.opname, instr.opcode)) |
| 752 | LOAD_FAST (124) |
| 753 | LOAD_CONST (100) |
| 754 | BINARY_ADD (23) |
| 755 | RETURN_VALUE (83) |
| 756 | >>> bytecode.dis().splitlines() # doctest: +NORMALIZE_WHITESPACE |
| 757 | [' 1 0 LOAD_FAST 0 (x)', |
| 758 | ' --> 3 LOAD_CONST 1 (1)', |
| 759 | ' 6 BINARY_ADD', |
| 760 | ' 7 RETURN_VALUE'] |
| 761 | |
| 762 | :class:`~dis.Bytecode` also has a class method, |
| 763 | :meth:`~dis.Bytecode.from_traceback`, that provides the ability to manipulate a |
| 764 | traceback (that is, ``print(Bytecode.from_traceback(tb).dis())`` is equivalent |
| 765 | to ``distb(tb)``). |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 766 | |
Nick Coghlan | 50c48b8 | 2013-11-23 00:57:00 +1000 | [diff] [blame] | 767 | (Contributed by Nick Coghlan, Ryan Kelly and Thomas Kluyver in :issue:`11816` |
| 768 | and Claudiu Popa in :issue:`17916`) |
Nick Coghlan | b39fd0c | 2013-05-06 23:59:20 +1000 | [diff] [blame] | 769 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 770 | New function :func:`~dis.stack_effect` computes the effect on the Python stack |
| 771 | of a given opcode and argument, information that is not otherwise available. |
| 772 | (Contributed by Larry Hastings in :issue:`19722`.) |
| 773 | |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 774 | |
R David Murray | 5a9d706 | 2012-11-21 15:09:21 -0500 | [diff] [blame] | 775 | doctest |
| 776 | ------- |
| 777 | |
R David Murray | 473f45b | 2013-12-27 17:01:16 -0500 | [diff] [blame] | 778 | A new :ref:`option flag <doctest-options>`, :data:`~doctest.FAIL_FAST`, halts |
| 779 | test running as soon as the first failure is detected. (Contributed by R. |
| 780 | David Murray and Daniel Urban in :issue:`16522`.) |
R David Murray | 5707d50 | 2013-06-23 14:24:13 -0400 | [diff] [blame] | 781 | |
R David Murray | 473f45b | 2013-12-27 17:01:16 -0500 | [diff] [blame] | 782 | The :mod:`doctest` command line interface now uses :mod:`argparse`, and has two |
| 783 | new options, ``-o`` and ``-f``. ``-o`` allows :ref:`doctest options |
| 784 | <doctest-options>` to be specified on the command line, and ``-f`` is a |
| 785 | shorthand for ``-o FAIL_FAST`` (to parallel the similar option supported by the |
| 786 | :mod:`unittest` CLI). (Contributed by R. David Murray in :issue:`11390`.) |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 787 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 788 | :mod:`doctest` will now find doctests in extension module ``__doc__`` strings. |
| 789 | (Contributed by Zachary Ware in :issue:`3158`.) |
| 790 | |
R David Murray | 8e37d5d | 2013-04-13 14:49:48 -0400 | [diff] [blame] | 791 | |
R David Murray | bb17d2b | 2013-08-09 16:15:28 -0400 | [diff] [blame] | 792 | email |
| 793 | ----- |
| 794 | |
| 795 | :meth:`~email.message.Message.as_string` now accepts a *policy* argument to |
| 796 | override the default policy of the message when generating a string |
| 797 | representation of it. This means that ``as_string`` can now be used in more |
| 798 | circumstances, instead of having to create and use a :mod:`~email.generator` in |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 799 | order to pass formatting parameters to its ``flatten`` method. (Contributed by |
| 800 | R. David Murray in :issue:`18600`.) |
R David Murray | bb17d2b | 2013-08-09 16:15:28 -0400 | [diff] [blame] | 801 | |
| 802 | New method :meth:`~email.message.Message.as_bytes` added to produce a bytes |
| 803 | representation of the message in a fashion similar to how ``as_string`` |
| 804 | produces a string representation. It does not accept the *maxheaderlen* |
| 805 | argument, but does accept the *unixfrom* and *policy* arguments. The |
| 806 | :class:`~email.message.Message` :meth:`~email.message.Message.__bytes__` method |
| 807 | calls it, meaning that ``bytes(mymsg)`` will now produce the intuitive |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 808 | result: a bytes object containing the fully formatted message. (Contributed |
| 809 | by R. David Murray in :issue:`18600`.) |
R David Murray | bb17d2b | 2013-08-09 16:15:28 -0400 | [diff] [blame] | 810 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 811 | The :meth:`.Message.set_param` message now accepts a *replace* keyword argument. |
| 812 | When specified, the associated header will be updated without changing |
| 813 | its location in the list of headers. For backward compatibility, the default |
| 814 | is ``False``. (Contributed by R. David Murray in :issue:`18891`.) |
| 815 | |
R David Murray | bb17d2b | 2013-08-09 16:15:28 -0400 | [diff] [blame] | 816 | |
R David Murray | 26b80cfd | 2013-12-20 17:26:52 -0500 | [diff] [blame] | 817 | .. _whatsnew_email_contentmanager: |
| 818 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 819 | A pair of new subclasses of :class:`~email.message.Message` have been added |
| 820 | (:class:`.EmailMessage` and :class:`.MIMEPart`), along with a new sub-module, |
| 821 | :mod:`~email.contentmanager` and a new :mod:`~email.policy` attribute |
| 822 | :attr:`~email.policy.EmailPolicy.content_manager`. All documentation is |
| 823 | currently in the new module, which is being added as part of email's new |
| 824 | :term:`provisional API`. These classes provide a number of new methods that |
| 825 | make extracting content from and inserting content into email messages much |
| 826 | easier. For details, see the :mod:`~email.contentmanager` documentation and |
| 827 | the :ref:`email-contentmanager-api-examples`. These API additions complete the |
| 828 | bulk of the work that was planned as part of the email6 project. The currently |
| 829 | provisional API is scheduled to become final in Python 3.5 (possibly with a few |
| 830 | minor additions in the area of error handling). (Contributed by R. David |
| 831 | Murray in :issue:`18891`.) |
R David Murray | 3da240f | 2013-10-16 22:48:40 -0400 | [diff] [blame] | 832 | |
R David Murray | bb17d2b | 2013-08-09 16:15:28 -0400 | [diff] [blame] | 833 | |
R David Murray | 4885f49 | 2014-02-02 11:11:01 -0500 | [diff] [blame] | 834 | filecmp |
| 835 | ------- |
| 836 | |
| 837 | A new :func:`~filecmp.clear_cache` function provides the ability to clear the |
| 838 | :mod:`filecmp` comparison cache, which uses :func:`os.stat` information to |
| 839 | determine if the file has changed since the last compare. This can be used, |
| 840 | for example, if the file might have been changed and re-checked in less time |
| 841 | than the resolution of a particular filesystem's file modification time field. |
| 842 | (Contributed by Mark Levitt in :issue:`18149`.) |
| 843 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 844 | New module attribute :data:`~filecmp.DEFAULT_IGNORES` provides the list of |
| 845 | directories that are used as the default value for the *ignore* parameter of |
| 846 | the :func:`~filecmp.dircmp` function. (Contributed by Eli Bendersky in |
| 847 | :issue:`15442`.) |
| 848 | |
R David Murray | 4885f49 | 2014-02-02 11:11:01 -0500 | [diff] [blame] | 849 | |
Victor Stinner | 854ffcb | 2013-06-21 00:36:30 +0200 | [diff] [blame] | 850 | functools |
| 851 | --------- |
| 852 | |
Andrew Kuchling | fe0f0b0 | 2014-01-31 12:17:53 -0500 | [diff] [blame] | 853 | The new :func:`~functools.partialmethod` descriptor brings partial argument |
Nick Coghlan | f4cb48a | 2013-11-03 16:41:46 +1000 | [diff] [blame] | 854 | application to descriptors, just as :func:`~functools.partial` provides |
| 855 | for normal callables. The new descriptor also makes it easier to get |
| 856 | arbitrary callables (including :func:`~functools.partial` instances) |
| 857 | to behave like normal instance methods when included in a class definition. |
Nick Coghlan | f4cb48a | 2013-11-03 16:41:46 +1000 | [diff] [blame] | 858 | (Contributed by Alon Horev and Nick Coghlan in :issue:`4331`) |
| 859 | |
R David Murray | 0a10216 | 2013-12-20 15:00:54 -0500 | [diff] [blame] | 860 | .. _whatsnew-singledispatch: |
| 861 | |
Nick Coghlan | f4cb48a | 2013-11-03 16:41:46 +1000 | [diff] [blame] | 862 | The new :func:`~functools.singledispatch` decorator brings support for |
| 863 | single-dispatch generic functions to the Python standard library. Where |
| 864 | object oriented programming focuses on grouping multiple operations on a |
| 865 | common set of data into a class, a generic function focuses on grouping |
| 866 | multiple implementations of an operation that allows it to work with |
| 867 | *different* kinds of data. |
| 868 | |
| 869 | .. seealso:: |
| 870 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 871 | :pep:`443` -- Single-dispatch generic functions |
Nick Coghlan | f4cb48a | 2013-11-03 16:41:46 +1000 | [diff] [blame] | 872 | PEP written and implemented by Łukasz Langa. |
Victor Stinner | 854ffcb | 2013-06-21 00:36:30 +0200 | [diff] [blame] | 873 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 874 | :func:`~functools.total_ordering` now supports a return value of |
| 875 | :const:`NotImplemented` from the underlying comparison function. (Contributed |
| 876 | by Katie Miller in :issue:`10042`.) |
| 877 | |
R David Murray | d265381 | 2013-12-27 14:06:15 -0500 | [diff] [blame] | 878 | A pure-python version of the :func:`~functools.partial` function is now in the |
| 879 | stdlib; in CPython it is overridden by the C accelerated version, but it is |
| 880 | available for other implementations to use. (Contributed by Brian Thorne in |
| 881 | :issue:`12428`.) |
| 882 | |
Nick Coghlan | e8c45d6 | 2013-07-28 20:00:01 +1000 | [diff] [blame] | 883 | |
R David Murray | 0e81463 | 2013-12-26 15:11:28 -0500 | [diff] [blame] | 884 | gc |
| 885 | -- |
| 886 | |
R David Murray | a101bdb | 2014-01-06 16:32:05 -0500 | [diff] [blame] | 887 | New function :func:`~gc.get_stats` returns a list of three per-generation |
| 888 | dictionaries containing the collections statistics since interpreter startup. |
| 889 | (Contributed by Antoine Pitrou in :issue:`16351`.) |
R David Murray | 0e81463 | 2013-12-26 15:11:28 -0500 | [diff] [blame] | 890 | |
| 891 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 892 | glob |
| 893 | ---- |
| 894 | |
| 895 | A new function :func:`~glob.escape` provides a way to escape special characters |
| 896 | in a filename so that they do not become part of the globbing expansion but are |
| 897 | instead matched literally. (Contributed by Serhiy Storchaka in :issue:`8402`.) |
| 898 | |
| 899 | |
Christian Heimes | e92ef13 | 2013-10-13 00:52:43 +0200 | [diff] [blame] | 900 | hashlib |
| 901 | ------- |
| 902 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 903 | A new :func:`hashlib.pbkdf2_hmac` function provides |
| 904 | the `PKCS#5 password-based key derivation function 2 |
| 905 | <http://en.wikipedia.org/wiki/PBKDF2>`_. (Contributed by Christian |
| 906 | Heimes in :issue:`18582`) |
| 907 | |
| 908 | The :attr:`~hashlib.hash.name` attribute of :mod:`hashlib` hash objects is now |
| 909 | a formally supported interface. It has always existed in CPython's |
| 910 | :mod:`hashlib` (although it did not return lower case names for all supported |
| 911 | hashes), but it was not a public interface and so some other Python |
| 912 | implementations have not previously supported it. (Contributed by Jason R. |
| 913 | Coombs in :issue:`18532`.) |
Christian Heimes | e92ef13 | 2013-10-13 00:52:43 +0200 | [diff] [blame] | 914 | |
| 915 | |
R David Murray | a56d4e8 | 2014-02-02 12:50:48 -0500 | [diff] [blame] | 916 | hmac |
| 917 | ---- |
| 918 | |
| 919 | :mod:`hmac` now accepts ``bytearray`` as well as ``bytes`` for the *key* |
| 920 | argument to the :func:`~hmac.new` function, and the *msg* parameter to both the |
| 921 | :func:`~hmac.new` function and the :meth:`~hmac.HMAC.update` method now |
| 922 | accepts any type supported by the :mod:`hashlib` module. (Contributed |
| 923 | by Jonas Borgström in :issue:`18240`.) |
| 924 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 925 | The *digestmod* argument to the :func:`hmac.new` function may now be any hash |
| 926 | digest name recognized by :mod:`hashlib`. In addition, the current behavior in |
| 927 | which the value of *digestmod* defaults to ``MD5`` is deprecated: in a |
| 928 | future version of Python there will be no default value. (Contributed by |
| 929 | Christian Heimes in :issue:`17276`.) |
| 930 | |
| 931 | With the addition of :attr:`~hmac.HMAC.block_size` and :attr:`~hmac.HMAC.name` |
| 932 | attributes (and the formal documentation of the :attr:`~hmac.HMAC.digest_size` |
| 933 | attribute), the :mod:`hmac` module now conforms fully to the :pep:`247` API. |
| 934 | (Contributed by Christian Heimes in :issue:`18775`.) |
| 935 | |
R David Murray | a56d4e8 | 2014-02-02 12:50:48 -0500 | [diff] [blame] | 936 | |
Ezio Melotti | 250a06c | 2013-11-25 06:18:47 +0200 | [diff] [blame] | 937 | html |
| 938 | ---- |
| 939 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 940 | New function :func:`~html.unescape` function converts HTML5 character references to |
| 941 | the corresponding Unicode characters. (Contributed by Ezio Melotti in |
| 942 | :issue:`2927`) |
Ezio Melotti | 250a06c | 2013-11-25 06:18:47 +0200 | [diff] [blame] | 943 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 944 | :class:`~html.parser.HTMLParser` accepts a new keyword argument |
| 945 | *convert_charrefs* that, when ``True``, automatically converts all character |
| 946 | references. For backward-compatibility, its value defaults to ``False``, but |
| 947 | it will change to ``True`` in a future version of Python, so you are invited to |
| 948 | set it explicitly and update your code to use this new feature. (Contributed |
| 949 | by Ezio Melotti in :issue:`13633`) |
Ezio Melotti | 250a06c | 2013-11-25 06:18:47 +0200 | [diff] [blame] | 950 | |
| 951 | The *strict* argument of :class:`~html.parser.HTMLParser` is now deprecated. |
Ezio Melotti | 250a06c | 2013-11-25 06:18:47 +0200 | [diff] [blame] | 952 | (Contributed by Ezio Melotti in :issue:`15114`) |
| 953 | |
| 954 | |
R David Murray | a475a8d | 2014-01-03 13:03:00 -0500 | [diff] [blame] | 955 | http |
| 956 | ---- |
| 957 | |
| 958 | :meth:`~http.server.BaseHTTPRequestHandler.send_error` now accepts an |
Zachary Ware | 335957e | 2014-01-13 16:08:54 -0600 | [diff] [blame] | 959 | optional additional *explain* parameter which can be used to provide an |
R David Murray | a475a8d | 2014-01-03 13:03:00 -0500 | [diff] [blame] | 960 | extended error description, overriding the hardcoded default if there is one. |
| 961 | This extended error description will be formatted using the |
| 962 | :attr:`~http.server.HTTP.error_message_format` attribute and sent as the body |
| 963 | of the error response. (Contributed by Karl Cow in :issue:`12921`.) |
| 964 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 965 | The :mod:`http.server` :ref:`command line interface <http-server-cli>` now has |
| 966 | a ``-b/--bind`` option that causes the server to listen on a specific address. |
| 967 | (Contributed by Malte Swart in :issue:`17764`.) |
| 968 | |
R David Murray | a475a8d | 2014-01-03 13:03:00 -0500 | [diff] [blame] | 969 | |
R David Murray | d265381 | 2013-12-27 14:06:15 -0500 | [diff] [blame] | 970 | importlib |
| 971 | --------- |
| 972 | |
| 973 | The :class:`~importlib.abc.InspectLoader` ABC defines a new method, |
| 974 | :meth:`~importlib.abc.InspectLoader.source_to_code` that accepts source |
| 975 | data and a path and returns a code object. The default implementation |
| 976 | is equivalent to ``compile(data, path, 'exec', dont_inherit=True)``. |
| 977 | (Contributed by Eric Snow and Brett Cannon in :issue:`15627`.) |
| 978 | |
R David Murray | 0ae7ae1 | 2014-01-08 18:16:02 -0500 | [diff] [blame] | 979 | :class:`~importlib.abc.InspectLoader` also now has a default implementation |
| 980 | for the :meth:`~importlib.abc.InspectLoader.get_code` method. However, |
| 981 | it will normally be desirable to override the default implementation |
| 982 | for performance reasons. (Contributed by Brett Cannon in :issue:`18072`.) |
| 983 | |
R David Murray | 70e04f5 | 2014-02-02 10:50:17 -0500 | [diff] [blame] | 984 | The :func:`~importlib.reload` function has been moved from :mod:`imp` to |
| 985 | :mod:`importlib` as part of the :mod:`imp` module deprecation. (Contributed by |
| 986 | Berker Peksag in :issue:`18193`.) |
R David Murray | 8c561b5 | 2014-02-01 12:27:07 -0500 | [diff] [blame] | 987 | |
R David Murray | 900aeb7 | 2014-02-02 11:32:31 -0500 | [diff] [blame] | 988 | :mod:`importlib.util` now has a :data:`~importlib.util.MAGIC_NUMBER` attribute |
| 989 | providing access to the bytecode version number. This replaces the |
| 990 | :func:`~imp.get_magic` function in the deprecated :mod:`imp` module. |
| 991 | (Contributed by Brett Cannon in :issue:`18192`.) |
| 992 | |
| 993 | New :mod:`importlib.util` functions :func:`~importlib.util.cache_from_source` |
| 994 | and :func:`~importlib.util.source_from_cache` replace the same-named functions |
| 995 | in the deprecated :mod:`imp` module. (Contributed by Brett Cannon in |
| 996 | :issue:`18194`.) |
| 997 | |
R David Murray | 5147e00 | 2014-02-02 12:19:57 -0500 | [diff] [blame] | 998 | The :mod:`importlib` bootstrap :class:`.NamespaceLoader` now conforms to |
| 999 | the :class:`.InspectLoader` ABC, which means that ``runpy`` and |
| 1000 | ``python -m`` can now be used with namespace packages. (Contributed |
| 1001 | by Brett Cannon in :issue:`18058`.) |
| 1002 | |
R David Murray | a56d4e8 | 2014-02-02 12:50:48 -0500 | [diff] [blame] | 1003 | :mod:`importlib.util` has a new function :func:`~importlib.util.decode_source` |
| 1004 | that decodes source from bytes using universal newline processing. This is |
| 1005 | useful for implementing :meth:`.InspectLoader.get_source` methods. |
| 1006 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1007 | :class:`importlib.machinery.ExtensionFileLoader` now has a |
| 1008 | :meth:`~importlib.machinery.ExtensionFileLoader.get_filename` method. This was |
| 1009 | inadvertently omitted in the original implementation. (Contributed by Eric |
| 1010 | Snow in :issue:`19152`.) |
| 1011 | |
R David Murray | d265381 | 2013-12-27 14:06:15 -0500 | [diff] [blame] | 1012 | |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 1013 | inspect |
| 1014 | ------- |
| 1015 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1016 | The :mod:`inspect` module now offers a basic :ref:`command line interface |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1017 | <inspect-module-cli>` to quickly display source code and other |
| 1018 | information for modules, classes and functions. (Contributed by Claudiu Popa |
| 1019 | and Nick Coghlan in :issue:`18626`) |
Nick Coghlan | f94a16b | 2013-09-22 22:46:49 +1000 | [diff] [blame] | 1020 | |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 1021 | :func:`~inspect.unwrap` makes it easy to unravel wrapper function chains |
| 1022 | created by :func:`functools.wraps` (and any other API that sets the |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1023 | ``__wrapped__`` attribute on a wrapper function). (Contributed by |
| 1024 | Daniel Urban, Aaron Iles and Nick Coghlan in :issue:`13266`) |
| 1025 | |
| 1026 | As part of the implementation of the new :mod:`enum` module, the |
| 1027 | :mod:`inspect` module now has substantially better support for custom |
| 1028 | ``__dir__`` methods and dynamic class attributes provided through |
| 1029 | metaclasses (Contributed by Ethan Furman in :issue:`18929` and |
| 1030 | :issue:`19030`) |
| 1031 | |
Yury Selivanov | d82eddc | 2014-01-29 11:24:39 -0500 | [diff] [blame] | 1032 | :func:`~inspect.getfullargspec` and :func:`~inspect.getargspec` |
| 1033 | now use the :func:`~inspect.signature` API. This allows them to |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1034 | support a much broader range of callables, including those with |
| 1035 | ``__signature__`` attributes, those with metadata provided by argument |
| 1036 | clinic, :func:`functools.partial` objects and more. Note that, unlike |
| 1037 | :func:`~inspect.signature`, these functions still ignore ``__wrapped__`` |
| 1038 | attributes, and report the already bound first argument for bound methods, |
| 1039 | so it is still necessary to update your code to use |
| 1040 | :func:`~inspect.signature` directly if those features are desired. |
| 1041 | (Contributed by Yury Selivanov in :issue:`17481`) |
Yury Selivanov | d82eddc | 2014-01-29 11:24:39 -0500 | [diff] [blame] | 1042 | |
Yury Selivanov | 63da7c7 | 2014-01-31 14:48:37 -0500 | [diff] [blame] | 1043 | :func:`~inspect.signature` now supports duck types of CPython functions, |
| 1044 | which adds support for functions compiled with Cython. (Contributed |
| 1045 | by Stefan Behnel and Yury Selivanov in :issue:`17159`) |
| 1046 | |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 1047 | |
Nick Coghlan | 96bb437 | 2014-02-09 09:18:26 +1000 | [diff] [blame] | 1048 | ipaddress |
| 1049 | --------- |
| 1050 | |
| 1051 | :mod:`ipaddress` was added to the standard library in Python 3.3 as a |
| 1052 | :term:`provisional API`. With the release of Python 3.4, this qualification |
| 1053 | has been removed: :mod:`ipaddress` is now considered a stable API, covered |
| 1054 | by the normal standard library requirements to maintain backwards |
| 1055 | compatibility. |
| 1056 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1057 | A new :attr:`~ipaddress.IPv4Address.is_global` property is ``True`` if |
| 1058 | an address is globally routeable. (Contributed by Peter Moody in |
| 1059 | :issue:`17400`.) |
| 1060 | |
Nick Coghlan | 96bb437 | 2014-02-09 09:18:26 +1000 | [diff] [blame] | 1061 | |
R David Murray | 9cf617b | 2014-01-04 18:55:01 -0500 | [diff] [blame] | 1062 | logging |
| 1063 | ------- |
| 1064 | |
| 1065 | The :class:`~logging.handlers.TimedRotatingFileHandler` has a new *atTime* |
| 1066 | parameter that can be used to specify the time of day when rollover should |
| 1067 | happen. (Contributed by Ronald Oussoren in :issue:`9556`.) |
| 1068 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1069 | :class:`~logging.handlers.SocketHandler` and |
| 1070 | :class:`~logging.handlers.DatagramHandler` now support Unix domain sockets (by |
| 1071 | setting *port* to ``None``). (Contributed by Vinay Sajip in commit |
| 1072 | ce46195b56a9.) |
| 1073 | |
| 1074 | :func:`~logging.config.fileConfig` now accepts a |
| 1075 | :class:`configparser.RawConfigParser` subclass instance for the *fname* |
| 1076 | parameter. This facilitates using a configuration file when logging |
| 1077 | configuration is just a part of the overall application configuration, or where |
| 1078 | the application modifies the configuration before passing it to |
| 1079 | :func:`~logging.config.fileConfig`. (Contributed by Vinay Sajip in |
| 1080 | :issue:`16110`.) |
| 1081 | |
| 1082 | Logging configuration data received from a socket via the |
| 1083 | :func:`logging.config.listen` function can now be validated before being |
| 1084 | processed by supplying a verification function as the argument to the new |
| 1085 | *verify* keyword argument. (Contributed by Vinay Sajip in :issue:`15452`.) |
| 1086 | |
R David Murray | 9cf617b | 2014-01-04 18:55:01 -0500 | [diff] [blame] | 1087 | |
R David Murray | 8f7664a | 2013-12-22 20:40:11 -0500 | [diff] [blame] | 1088 | .. _whatsnew-marshal-3: |
| 1089 | |
| 1090 | marshal |
| 1091 | ------- |
| 1092 | |
| 1093 | The default :mod:`marshal` version has been bumped to 3. The code implementing |
| 1094 | the new version restores the Python2 behavior of recording only one copy of |
| 1095 | interned strings and preserving the interning on deserialization, and extends |
| 1096 | this "one copy" ability to any object type (including handling recursive |
| 1097 | references). This reduces both the size of ``.pyc`` files and the amount of |
| 1098 | memory a module occupies in memory when it is loaded from a ``.pyc`` (or |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1099 | ``.pyo``) file. (Contributed by Kristján Valur Jónsson in :issue:`16475`, |
| 1100 | with additional speedups by Antoine Pitrou in :issue:`19219`.) |
R David Murray | 8f7664a | 2013-12-22 20:40:11 -0500 | [diff] [blame] | 1101 | |
| 1102 | |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1103 | mmap |
| 1104 | ---- |
| 1105 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1106 | mmap objects can now be :mod:`weakref`\ ed. (Contributed by Valerie Lambert in |
| 1107 | :issue:`4885`.) |
R David Murray | 57fcf76 | 2014-01-03 23:31:54 -0500 | [diff] [blame] | 1108 | |
R David Murray | 33ef1ae | 2013-12-31 16:04:50 -0500 | [diff] [blame] | 1109 | |
Richard Oudkerk | 84ed9a6 | 2013-08-14 15:35:41 +0100 | [diff] [blame] | 1110 | multiprocessing |
| 1111 | --------------- |
| 1112 | |
R David Murray | ac18622 | 2013-12-20 17:23:57 -0500 | [diff] [blame] | 1113 | .. _whatsnew-multiprocessing-no-fork: |
| 1114 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1115 | On Unix two new :ref:`start methods <multiprocessing-start-methods>`, |
| 1116 | (``spawn`` and ``forkserver``, have been added for starting processes using |
R David Murray | ac18622 | 2013-12-20 17:23:57 -0500 | [diff] [blame] | 1117 | :mod:`multiprocessing`. These make the mixing of processes with threads more |
| 1118 | robust, and the ``spawn`` method matches the semantics that multiprocessing has |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1119 | always used on Windows. New function |
| 1120 | :func:`~multiprocessing.get_all_start_methods` reports all start methods |
| 1121 | available on the platform, :func:`~multiprocessing.get_start_method` reports |
| 1122 | the current start method, and :func:`~multiprocessing.set_start_method` sets |
| 1123 | the start method. (Contributed by Richard Oudkerk in :issue:`8713`). |
Richard Oudkerk | 84ed9a6 | 2013-08-14 15:35:41 +0100 | [diff] [blame] | 1124 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1125 | :mod:`multiprocessing` also now has the concept of a ``context``, which |
| 1126 | determines how child processes are created. New function |
| 1127 | :func:`~multiprocessing.get_context` returns a context that uses a specified |
| 1128 | start method. It has the same API as the :mod:`multiprocessing` module itself, |
| 1129 | so you can use it to create :class:`~multiprocessing.pool.Pool`\ s and other |
| 1130 | objects that will operate within that context. This allows a framework and an |
| 1131 | application or different parts of the same application to use multiprocessing |
| 1132 | without interfering with each other. (Contributed by Richard Oudkerk in |
| 1133 | :issue:`18999`.) |
| 1134 | |
| 1135 | Except when using the old *fork* start method, child processes no longer |
| 1136 | inherit unneeded handles/file descriptors from their parents (part of |
| 1137 | :issue:`8713`). |
Richard Oudkerk | 84ed9a6 | 2013-08-14 15:35:41 +0100 | [diff] [blame] | 1138 | |
Nick Coghlan | 9a76735 | 2013-12-17 22:17:26 +1000 | [diff] [blame] | 1139 | :mod:`multiprocessing` now relies on :mod:`runpy` (which implements the |
| 1140 | ``-m`` switch) to initialise ``__main__`` appropriately in child processes |
| 1141 | when using the ``spawn`` or ``forkserver`` start methods. This resolves some |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1142 | edge cases where combining multiprocessing, the ``-m`` command line switch, |
Nick Coghlan | 9a76735 | 2013-12-17 22:17:26 +1000 | [diff] [blame] | 1143 | and explicit relative imports could cause obscure failures in child |
| 1144 | processes. (Contributed by Nick Coghlan in :issue:`19946`) |
| 1145 | |
Richard Oudkerk | 84ed9a6 | 2013-08-14 15:35:41 +0100 | [diff] [blame] | 1146 | |
R David Murray | 9835827 | 2014-01-05 20:52:06 -0500 | [diff] [blame] | 1147 | operator |
| 1148 | -------- |
| 1149 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1150 | New function :func:`~operator.length_hint` provides an implementation of the |
| 1151 | specification for how the :meth:`~object.__length_hint__` special method should |
| 1152 | be used, as part of the :pep:`424` formal specification of this language |
| 1153 | feature. (Contributed by Armin Ronacher in :issue:`16148`.) |
| 1154 | |
R David Murray | 9835827 | 2014-01-05 20:52:06 -0500 | [diff] [blame] | 1155 | There is now a pure-python version of the :mod:`operator` module available for |
| 1156 | reference and for use by alternate implementations of Python. (Contributed by |
| 1157 | Zachary Ware in :issue:`16694`.) |
| 1158 | |
| 1159 | |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 1160 | os |
| 1161 | -- |
| 1162 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1163 | There are new functions to get and set the :ref:`inheritable flag |
| 1164 | <fd_inheritance>` of a file descriptor (:func:`os.get_inheritable`, |
| 1165 | :func:`os.set_inheritable`) or a Windows handle |
| 1166 | (:func:`os.get_handle_inheritable`, :func:`os.set_handle_inheritable`). |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 1167 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1168 | New function :func:`~os.cpu_count` reports the number of CPUs available on the |
| 1169 | platform on which Python is running (or ``None`` if the count can't be |
| 1170 | determined). The :func:`multiprocessing.cpu_count` function is now implemented |
| 1171 | in terms of this function). (Contributed by Trent Nelson, Yogesh Chaudhari, |
| 1172 | Victor Stinner, and Charles-François Natali in :issue:`17914`.) |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 1173 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1174 | :func:`os.path.samestat` is now available on the Windows platform (and the |
| 1175 | :func:`os.path.samefile` implementation is now shared between Unix and |
| 1176 | Windows). (Contributed by Brian Curtin in :issue:`11939`.) |
| 1177 | |
| 1178 | :func:`os.path.ismount` now recognizes volumes mounted below a drive |
| 1179 | root on Windows. (Contributed by Tim Golden in :issue:`9035`.) |
| 1180 | |
| 1181 | :func:`os.open` supports two new flags on platforms that provide them, |
| 1182 | :data:`~os.O_PATH` (un-opened file descriptor), and :data:`~os.O_TMPFILE` |
| 1183 | (unnamed temporary file; as of 3.4.0 release available only on Linux systems |
| 1184 | with a kernel version of 3.11 or newer that have uapi headers). (Contributed |
| 1185 | by Christian Heimes in :issue:`18673` and Benjamin Peterson, respectively.) |
R David Murray | 66bf12a | 2014-01-08 17:21:22 -0500 | [diff] [blame] | 1186 | |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 1187 | |
R David Murray | 78d692f | 2013-10-10 17:23:26 -0400 | [diff] [blame] | 1188 | pdb |
| 1189 | --- |
| 1190 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1191 | :mod:`pdb` has been enhanced to handle generators, :keyword:`yield`, and |
| 1192 | ``yield from`` in a more useful fashion. This is especially helpful when |
| 1193 | debugging :mod:`asyncio` based programs. (Contributed by Andrew Svetlov and |
| 1194 | Xavier de Gaye in :issue:`16596`.) |
| 1195 | |
R David Murray | 78d692f | 2013-10-10 17:23:26 -0400 | [diff] [blame] | 1196 | The ``print`` command has been removed from :mod:`pdb`, restoring access to the |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1197 | Python :func:`print` function from the pdb command line. Python2's ``pdb`` did |
| 1198 | not have a ``print`` command; instead, entering ``print`` executed the |
| 1199 | ``print`` statement. In Python3 ``print`` was mistakenly made an alias for the |
| 1200 | pdb :pdbcmd:`p` command. ``p``, however, prints the ``repr`` of its argument, |
| 1201 | not the ``str`` like the Python2 ``print`` command did. Worse, the Python3 |
| 1202 | ``pdb print`` command shadowed the Python3 ``print`` function, making it |
| 1203 | inaccessible at the ``pdb`` prompt. (Contributed by Connor Osborn in |
| 1204 | :issue:`18764`.) |
R David Murray | 78d692f | 2013-10-10 17:23:26 -0400 | [diff] [blame] | 1205 | |
| 1206 | |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 1207 | .. _whatsnew-protocol-4: |
| 1208 | |
R David Murray | 5ea9524 | 2013-12-24 15:59:57 -0500 | [diff] [blame] | 1209 | pickle |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 1210 | ------ |
| 1211 | |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 1212 | :mod:`pickle` now supports (but does not use by default) a new pickle protocol, |
| 1213 | protocol 4. This new protocol addresses a number of issues that were present |
| 1214 | in previous protocols, such as the serialization of nested classes, very large |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1215 | strings and containers, and classes whose :meth:`__new__` method takes |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 1216 | keyword-only arguments. It also provides some efficiency improvements. |
| 1217 | |
| 1218 | .. seealso:: |
| 1219 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 1220 | :pep:`3154` -- Pickle protocol 4 |
R David Murray | 809487e | 2013-12-22 20:49:40 -0500 | [diff] [blame] | 1221 | PEP written by Antoine Pitrou and implemented by Alexandre Vassalotti. |
| 1222 | |
| 1223 | |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 1224 | plistlib |
| 1225 | -------- |
| 1226 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1227 | :mod:`plistlib` now has an API that is similar to the standard pattern for |
| 1228 | stdlib serialization protocols, with new :func:`~plistlib.load`, |
| 1229 | :func:`~plistlib.dump`, :func:`~plistlib.loads`, and :func:`~plistlib.dumps` |
| 1230 | functions. (The older API is now deprecated.) In addition to the already |
| 1231 | supported XML plist format (:data:`~plistlib.FMT_XML`), it also now supports |
| 1232 | the binary plist format (:data:`~plistlib.FMT_BINARY`). (Contributed by Ronald |
| 1233 | Oussoren and others in :issue:`14455`). |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 1234 | |
| 1235 | |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1236 | poplib |
| 1237 | ------ |
| 1238 | |
R David Murray | 473f45b | 2013-12-27 17:01:16 -0500 | [diff] [blame] | 1239 | Two new methods have been added to :mod:`poplib`: :meth:`~poplib.POP3.capa`, |
| 1240 | which returns the list of capabilities advertised by the POP server, and |
| 1241 | :meth:`~poplib.POP3.stls`, which switches a clear-text POP3 session into an |
| 1242 | encrypted POP3 session if the POP server supports it. (Contributed by Lorenzo |
| 1243 | Catucci in :issue:`4473`.) |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1244 | |
| 1245 | |
Serhiy Storchaka | 7c411a4 | 2013-10-02 11:56:18 +0300 | [diff] [blame] | 1246 | pprint |
| 1247 | ------ |
| 1248 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1249 | The :mod:`pprint` module's :class:`~pprint.PrettyPrinter` class and its |
| 1250 | :func:`~pprint.pformat`, and :func:`~pprint.pprint` functions have a new |
| 1251 | option, *compact*, that controls how the output is formatted. Currently |
| 1252 | setting *compact* to ``True`` means that sequences will be printed with as many |
| 1253 | sequence elements as will fit within *width* on each (indented) line. |
| 1254 | (Contributed by Serhiy Storchaka in :issue:`19132`.) |
Serhiy Storchaka | 7c411a4 | 2013-10-02 11:56:18 +0300 | [diff] [blame] | 1255 | |
R David Murray | b231b2b | 2014-01-04 17:11:23 -0500 | [diff] [blame] | 1256 | Long strings are now wrapped using Python's normal line continuation |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1257 | syntax. (Contributed by Antoine Pitrou in :issue:`17150`). |
R David Murray | b231b2b | 2014-01-04 17:11:23 -0500 | [diff] [blame] | 1258 | |
Serhiy Storchaka | 7c411a4 | 2013-10-02 11:56:18 +0300 | [diff] [blame] | 1259 | |
R David Murray | 6e39015 | 2013-12-24 22:28:04 -0500 | [diff] [blame] | 1260 | pty |
| 1261 | --- |
| 1262 | |
| 1263 | :func:`pty.spawn` now returns the status value from :func:`os.waitpid` on |
| 1264 | the child process, instead of ``None``. (Contributed by Gregory P. Smith.) |
| 1265 | |
| 1266 | |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1267 | pydoc |
| 1268 | ----- |
| 1269 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1270 | The :mod:`pydoc` module is now based directly on the :func:`inspect.signature` |
| 1271 | introspection API, allowing it to provide signature information for a wider |
| 1272 | variety of callable objects. This change also means that ``__wrapped__`` |
| 1273 | attributes are now taken into account when displaying help information |
| 1274 | (Contributed by Larry Hastings in :issue:`19674`) |
| 1275 | |
| 1276 | The :mod:`pydoc` module no longer displays the ``self`` parameter for |
| 1277 | already bound methods. Instead, it aims to always display the exact current |
| 1278 | signature of the supplied callable (Contributed by Larry Hastings in |
| 1279 | :issue:`20710`) |
| 1280 | |
| 1281 | In addition to the changes that have been made to :mod:`pydoc` directly, |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1282 | its handling of custom ``__dir__`` methods and various descriptor |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1283 | behaviours has also been improved substantially by the underlying changes in |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1284 | the :mod:`inspect` module. |
| 1285 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1286 | As the :func:`help` builtin is based on :mod:`pydoc`, the above changes also |
| 1287 | affect the behaviour of :func:`help`. |
| 1288 | |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1289 | |
Serhiy Storchaka | 32eddc1 | 2013-11-23 23:20:30 +0200 | [diff] [blame] | 1290 | re |
| 1291 | -- |
| 1292 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1293 | New :func:`~re.fullmatch` function and :meth:`.regex.fullmatch` method anchor |
| 1294 | the pattern at both ends of the string to match. This provides a way to be |
| 1295 | explicit about the goal of the match, which avoids a class of subtle bugs where |
| 1296 | ``$`` characters get lost during code changes or the addition of alternatives |
| 1297 | to an existing regular expression. (Contributed by Matthew Barnett in |
| 1298 | :issue:`16203`.) |
Serhiy Storchaka | 32eddc1 | 2013-11-23 23:20:30 +0200 | [diff] [blame] | 1299 | |
Ezio Melotti | dd7e291 | 2013-11-25 23:20:20 +0200 | [diff] [blame] | 1300 | The repr of :ref:`regex objects <re-objects>` now includes the pattern |
| 1301 | and the flags; the repr of :ref:`match objects <match-objects>` now |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1302 | includes the start, end, and the part of the string that matched. (Contributed |
| 1303 | by Hugo Lopes Tavares and Serhiy Storchaka in :issue:`13592` and |
| 1304 | :issue:`17087`.) |
Ezio Melotti | dd7e291 | 2013-11-25 23:20:20 +0200 | [diff] [blame] | 1305 | |
| 1306 | |
Christian Heimes | b7bd5df | 2013-10-22 11:21:54 +0200 | [diff] [blame] | 1307 | resource |
| 1308 | -------- |
| 1309 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1310 | New :func:`~resource.prlimit` function, available on Linux platforms with a |
| 1311 | kernel version of 2.6.36 or later and glibc of 2.13 or later, provides the |
| 1312 | ability to query or set the resource limits for processes other than the one |
| 1313 | making the call. (Contributed by Christian Heimes in :issue:`16595`.) |
| 1314 | |
| 1315 | On Linux kernel version 2.6.36 or later, there are there are also some new |
| 1316 | Linux specific constants: :attr:`~resource.RLIMIT_MSGQUEUE`, |
| 1317 | :attr:`~resource.RLIMIT_NICE`, :attr:`~resource.RLIMIT_RTPRIO`, |
| 1318 | :attr:`~resource.RLIMIT_RTTIME`, and :attr:`~resource.RLIMIT_SIGPENDING`. |
| 1319 | (Contributed by Christian Heimes in :issue:`19324`.) |
| 1320 | |
| 1321 | On FreeBSD version 9 and later, there some new FreeBSD specific constants: |
| 1322 | :attr:`~resource.RLIMIT_SBSIZE`, :attr:`~resource.RLIMIT_SWAP`, and |
| 1323 | :attr:`~resource.RLIMIT_NPTS`. (Contributed by Claudiu Popa in |
| 1324 | :issue:`19343`.) |
Christian Heimes | b7bd5df | 2013-10-22 11:21:54 +0200 | [diff] [blame] | 1325 | |
R David Murray | 575fb31 | 2013-12-25 23:21:03 -0500 | [diff] [blame] | 1326 | |
R David Murray | 2bc930f | 2013-12-31 11:17:21 -0500 | [diff] [blame] | 1327 | select |
| 1328 | ------ |
| 1329 | |
| 1330 | :class:`~select.epoll` objects now support the context management protocol. |
| 1331 | When used in a :keyword:`with` statement, the :meth:`~select.epoll.close` |
| 1332 | method will be called automatically at the end of the block. (Contributed |
| 1333 | by Serhiy Storchaka in :issue:`16488`.) |
| 1334 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1335 | :class:`~select.devpoll` objects now have :meth:`~select.devpoll.fileno` and |
| 1336 | :meth:`~select.devpoll.close` methods, as well as a new attribute |
| 1337 | :attr:`~select.devpoll.closed`. (Contributed by Victor Stinner in |
| 1338 | :issue:`18794`.) |
| 1339 | |
R David Murray | 2bc930f | 2013-12-31 11:17:21 -0500 | [diff] [blame] | 1340 | |
R David Murray | 575fb31 | 2013-12-25 23:21:03 -0500 | [diff] [blame] | 1341 | shelve |
| 1342 | ------ |
| 1343 | |
| 1344 | :class:`~shelve.Shelf` instances may now be used in :keyword:`with` statements, |
| 1345 | and will be automatically closed at the end of the :keyword:`with` block. |
| 1346 | (Contributed by Filip Gruszczyński in :issue:`13896`.) |
| 1347 | |
| 1348 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1349 | shutil |
| 1350 | ------ |
| 1351 | |
| 1352 | :func:`~shutil.copyfile` now raises a specific :exc:`~shutil.Error` subclass, |
| 1353 | :exc:`~shutil.SameFileError`, when the source and destination are the same |
| 1354 | file, which allows an application to take appropriate action on this specific |
| 1355 | error. (Contributed by Atsuo Ishimoto and Hynek Schlawack in |
| 1356 | :issue:`1492704`.) |
| 1357 | |
| 1358 | |
R David Murray | f1e4fdc | 2014-01-21 18:30:42 -0500 | [diff] [blame] | 1359 | smtpd |
| 1360 | ----- |
| 1361 | |
| 1362 | The :class:`~smtpd.SMTPServer` and :class:`~smtpd.SMTPChannel` classes now |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1363 | accept a *map* keyword argument which, if specified, is passed in to |
R David Murray | f1e4fdc | 2014-01-21 18:30:42 -0500 | [diff] [blame] | 1364 | :class:`asynchat.async_chat` as its *map* argument. This allows an application |
| 1365 | to avoid affecting the global socket map. (Contributed by Vinay Sajip in |
| 1366 | :issue:`11959`.) |
| 1367 | |
| 1368 | |
R David Murray | 8e37d5d | 2013-04-13 14:49:48 -0400 | [diff] [blame] | 1369 | smtplib |
| 1370 | ------- |
| 1371 | |
R David Murray | 8a34596 | 2013-04-14 06:46:35 -0400 | [diff] [blame] | 1372 | :exc:`~smtplib.SMTPException` is now a subclass of :exc:`OSError`, which allows |
R David Murray | 8e37d5d | 2013-04-13 14:49:48 -0400 | [diff] [blame] | 1373 | both socket level errors and SMTP protocol level errors to be caught in one |
| 1374 | try/except statement by code that only cares whether or not an error occurred. |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1375 | (Contributed by Ned Jackson Lovely in :issue:`2118`). |
R David Murray | 8e37d5d | 2013-04-13 14:49:48 -0400 | [diff] [blame] | 1376 | |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 1377 | |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 1378 | socket |
| 1379 | ------ |
| 1380 | |
R David Murray | 33ef1ae | 2013-12-31 16:04:50 -0500 | [diff] [blame] | 1381 | The socket module now supports the :data:`~socket.CAN_BCM` protocol on |
| 1382 | platforms that support it. (Contributed by Brian Thorne in :issue:`15359`.) |
| 1383 | |
Georg Brandl | 5642ff9 | 2013-09-15 10:37:57 +0200 | [diff] [blame] | 1384 | Socket objects have new methods to get or set their :ref:`inheritable flag |
R David Murray | 33ef1ae | 2013-12-31 16:04:50 -0500 | [diff] [blame] | 1385 | <fd_inheritance>`, :meth:`~socket.socket.get_inheritable` and |
| 1386 | :meth:`~socket.socket.set_inheritable`. |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 1387 | |
R David Murray | 33ef1ae | 2013-12-31 16:04:50 -0500 | [diff] [blame] | 1388 | The ``socket.AF_*`` and ``socket.SOCK_*`` constants are now enumeration values |
| 1389 | using the new :mod:`enum` module. This allows meaningful names to be printed |
| 1390 | during debugging, instead of integer "magic numbers". |
Victor Stinner | daf4555 | 2013-08-28 00:53:59 +0200 | [diff] [blame] | 1391 | |
R David Murray | 66bf12a | 2014-01-08 17:21:22 -0500 | [diff] [blame] | 1392 | The :data:`~socket.AF_LINK` constant is now available on BSD and OSX. |
| 1393 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1394 | :func:`~socket.inet_pton` and :func:`~socket.inet_ntop` are now supported |
| 1395 | on Windows. (Contributed by Atsuo Ishimoto in :issue:`7171`.) |
| 1396 | |
R David Murray | 8b2d682 | 2013-12-31 15:06:05 -0500 | [diff] [blame] | 1397 | |
R David Murray | 9025f1c | 2014-01-02 13:44:18 -0500 | [diff] [blame] | 1398 | sqlite3 |
| 1399 | ------- |
| 1400 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1401 | A new boolean parameter to the :func:`~sqlite3.connect` function, *uri*, can be |
| 1402 | used to indicate that the *database* parameter is a ``uri`` (see the `SQLite |
| 1403 | URI documentation <http://www.sqlite.org/uri.html>`_). (Contributed by poq in |
| 1404 | :issue:`13773`.) |
R David Murray | 9025f1c | 2014-01-02 13:44:18 -0500 | [diff] [blame] | 1405 | |
| 1406 | |
Christian Heimes | 24cd4cf | 2013-06-22 19:31:58 +0200 | [diff] [blame] | 1407 | ssl |
| 1408 | --- |
| 1409 | |
R David Murray | 748bad2 | 2013-12-20 17:08:39 -0500 | [diff] [blame] | 1410 | .. _whatsnew-tls-11-12: |
Christian Heimes | 24cd4cf | 2013-06-22 19:31:58 +0200 | [diff] [blame] | 1411 | |
R David Murray | 748bad2 | 2013-12-20 17:08:39 -0500 | [diff] [blame] | 1412 | :data:`~ssl.PROTOCOL_TLSv1_1` and :data:`~ssl.PROTOCOL_TLSv1_2` (TLSv1.1 and |
| 1413 | TLSv1.2 support) have been added; support for these protocols is only available if |
| 1414 | Python is linked with OpenSSL 1.0.1 or later. (Contributed by Michele Orrù and |
| 1415 | Antoine Pitrou in :issue:`16692`) |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1416 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1417 | .. _whatsnew34-sslcontext: |
| 1418 | |
| 1419 | New function :func:`~ssl.create_default_context` provides a standard way to |
| 1420 | obtain an :class:`~ssl.SSLContext` whose settings are intended to be a |
| 1421 | reasonable balance between compatibility and security. These settings are |
| 1422 | more stringent than the defaults provided by the :class:`~ssl.SSLContext` |
| 1423 | constructor, and may be adjusted in the future, without prior deprecation, if |
| 1424 | best-practice security requirements change. The new recommended best |
| 1425 | practice for using stdlib libraries that support SSL is to use |
| 1426 | :func:`~ssl.create_default_context` to obtain an :class:`~ssl.SSLContext` |
| 1427 | object, modify it if needed, and then pass it as the *context* argument |
| 1428 | of the appropriate stdlib API. (Contributed by Christian Heimes |
| 1429 | in :issue:`19689`.) |
| 1430 | |
| 1431 | :class:`~ssl.SSLContext` method :meth:`~ssl.SSLContext.load_verify_locations` |
| 1432 | accepts a new optional argument *cadata*, which can be used to provide PEM or |
| 1433 | DER encoded certificates directly via strings or bytes, respectively. |
| 1434 | (Contributed by Christian Heimes in :issue:`18138`.) |
| 1435 | |
R David Murray | f1e4fdc | 2014-01-21 18:30:42 -0500 | [diff] [blame] | 1436 | New function :func:`~ssl.get_default_verify_paths` returns |
| 1437 | a named tuple of the paths and environment variables that the |
| 1438 | :meth:`~ssl.SSLContext.set_default_verify_paths` method uses to set |
| 1439 | OpenSSL's default ``cafile`` and ``capath``. This can be an aid in |
| 1440 | debugging default verification issues. (Contributed by Christian Heimes |
| 1441 | in :issue:`18143`.) |
| 1442 | |
| 1443 | :class:`~ssl.SSLContext` has a new method, |
| 1444 | :meth:`~ssl.SSLContext.cert_store_stats`, that reports the number of loaded |
| 1445 | ``X.509`` certs, ``X.509 CA`` certs, and certificate revocation lists (``crl``\ |
| 1446 | s), as well as a :meth:`~ssl.SSLContext.get_ca_certs` method that returns a |
| 1447 | list of the loaded ``CA`` certificates. (Contributed by Christian Heimes in |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1448 | :issue:`18147`.) |
| 1449 | |
| 1450 | If OpenSSL 0.9.8 or later is available, :class:`~ssl.SSLContext` has an new |
| 1451 | attribute :attr:`~ssl.SSLContext.verify_flags` that can be used to control the |
| 1452 | certificate verification process by setting it to some combination of the new |
| 1453 | constants :data:`~ssl.VERIFY_DEFAULT`, :data:`~ssl.VERIFY_CRL_CHECK_LEAF`, |
| 1454 | :data:`~ssl.VERIFY_CRL_CHECK_CHAIN`, or :data:`~ssl.VERIFY_X509_STRICT`. |
| 1455 | OpenSSL does not do any CRL verification by default. (Contributed by |
| 1456 | Christien Heimes in :issue:`8813`.) |
| 1457 | |
| 1458 | New :class:`~ssl.SSLContext` method :meth:`~ssl.SSLContext.load_default_certs` |
| 1459 | loads a set of dfault "certificate authority" (CA) certificates from default |
| 1460 | locations, which vary according to the platform. It can be used to load both |
| 1461 | TLS web server authentication certificates |
| 1462 | (``purpose=``:data:`~ssl.Purpose.SERVER_AUTH`) for a client to use to verify a |
| 1463 | server, and certificates for a server to use in verifying client certificates |
| 1464 | (``purpose=``:data:`~ssl.Purpose.CLIENT_AUTH`). (Contributed by Christian |
| 1465 | Heimes in :issue:`19292`.) |
| 1466 | |
| 1467 | .. _whatsnew34-win-cert-store: |
Christian Heimes | 24cd4cf | 2013-06-22 19:31:58 +0200 | [diff] [blame] | 1468 | |
R David Murray | 8c561b5 | 2014-02-01 12:27:07 -0500 | [diff] [blame] | 1469 | Two new windows-only functions, :func:`~ssl.enum_certificates` and |
| 1470 | :func:`~ssl.enum_crls` provide the ability to retrieve certificates, |
| 1471 | certificate information, and CRLs from the Windows cert store. (Contributed |
| 1472 | by Christian Heimes in :issue:`17134`.) |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1473 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1474 | .. _whatsnew34-sni: |
| 1475 | |
| 1476 | Support for server-side SNI (Server Name Indication) using the new |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1477 | :meth:`ssl.SSLContext.set_servername_callback` method. |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1478 | (Contributed by Daniel Black in :issue:`8109`.) |
| 1479 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1480 | The dictionary returned by :meth:`.SSLSocket.getpeercert` contains additional |
| 1481 | ``X509v3`` extension items: ``crlDistributionPoints``, ``calIssuers``, and |
| 1482 | ``OCSP`` URIs. (Contributed by Christian Heimes in :issue:`18379`.) |
| 1483 | |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1484 | |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 1485 | stat |
| 1486 | ---- |
| 1487 | |
| 1488 | The :mod:`stat` module is now backed by a C implementation in :mod:`_stat`. A C |
| 1489 | implementation is required as most of the values aren't standardized and |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1490 | are platform-dependent. (Contributed by Christian Heimes in :issue:`11016`.) |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 1491 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1492 | The module supports new :mod:`~stat.ST_MODE` flags, :mod:`~stat.S_IFDOOR`, |
| 1493 | :attr:`~stat.S_IFPORT`, and :attr:`~stat.S_IFWHT`. (Contributed by |
| 1494 | Christian Hiemes in :issue:`11016`.) |
Antoine Pitrou | d6cbd34 | 2013-08-12 20:48:15 +0200 | [diff] [blame] | 1495 | |
| 1496 | |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1497 | struct |
| 1498 | ------ |
| 1499 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1500 | New function :mod:`~struct.iter_unpack` and a new |
| 1501 | :meth:`struct.Struct.iter_unpack` method on compiled formats provide streamed |
| 1502 | unpacking of a buffer containing repeated instances of a given format of data. |
| 1503 | (Contributed by Antoine Pitrou in :issue:`17804`.) |
R David Murray | 9835827 | 2014-01-05 20:52:06 -0500 | [diff] [blame] | 1504 | |
| 1505 | |
| 1506 | subprocess |
| 1507 | ---------- |
| 1508 | |
| 1509 | :func:`~subprocess.check_output` now accepts an *input* argument that can |
| 1510 | be used to provide the contents of ``stdin`` for the command that is run. |
| 1511 | (Contributed by Zack Weinberg in :issue:`16624`.) |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1512 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1513 | :func:`~subprocess.getstatus` and :func:`~subprocess.getstatusoutput` now |
| 1514 | work on Windows. This change was actually inadvertently made in 3.3.4. |
| 1515 | (Contributed by Tim Golden in :issue:`10197`.) |
| 1516 | |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1517 | |
Serhiy Storchaka | e06a896 | 2013-09-04 00:43:03 +0300 | [diff] [blame] | 1518 | sunau |
| 1519 | ----- |
| 1520 | |
| 1521 | The :meth:`~sunau.getparams` method now returns a namedtuple rather than a |
| 1522 | plain tuple. (Contributed by Claudiu Popa in :issue:`18901`.) |
| 1523 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1524 | :meth:`sunau.open` now supports the context manager protocol: when used in a |
| 1525 | :keyword:`with` block, the ``close`` method of the returned object will be |
| 1526 | called automatically at the end of the block. (Contributed by Serhiy Storchaka |
| 1527 | in :issue:`18878`.) |
| 1528 | |
| 1529 | :meth:`.AU_write.setsampwidth` now supports 24 bit samples, thus adding |
| 1530 | support for writing 24 sample using the module. (Contributed by |
| 1531 | Serhiy Storchaka in :issue:`19261`.) |
| 1532 | |
| 1533 | The :meth:`~sunau.AU_write.writeframesraw` and |
| 1534 | :meth:`~sunau.AU_write.writeframes` methods now accept any :term:`bytes-like |
| 1535 | object`. (Contributed by Serhiy Storchaka in :issue:`8311`.) |
Serhiy Storchaka | 34d2013 | 2013-09-05 17:01:53 +0300 | [diff] [blame] | 1536 | |
Serhiy Storchaka | e06a896 | 2013-09-04 00:43:03 +0300 | [diff] [blame] | 1537 | |
R David Murray | d17aba7 | 2013-12-24 14:46:23 -0500 | [diff] [blame] | 1538 | sys |
| 1539 | --- |
| 1540 | |
| 1541 | New function :func:`sys.getallocatedblocks` returns the current number of |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1542 | blocks allocated by the interpreter. (In CPython with the default |
R David Murray | d17aba7 | 2013-12-24 14:46:23 -0500 | [diff] [blame] | 1543 | ``--with-pymalloc`` setting, this is allocations made through the |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1544 | :c:func:`PyObject_Malloc` API.) This can be useful for tracking memory leaks, |
R David Murray | d17aba7 | 2013-12-24 14:46:23 -0500 | [diff] [blame] | 1545 | especially if automated via a test suite. (Contributed by Antoine Pitrou |
| 1546 | in :issue:`13390`.) |
| 1547 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1548 | When the Python interpreter starts in :ref:`interactive mode |
| 1549 | <tut-interactive>`, it checks for an :data:`~sys.__interactivehook__` attribute |
| 1550 | on the :mod:`sys` module. If the attribute exists, its value is called with no |
| 1551 | arguments just before interactive mode is started. The check is made after the |
| 1552 | :envvar:`PYTHONSTARTUP` file is read, so it can be set there. The :mod:`site` |
| 1553 | module :ref:`sets it <rlcompleter-config>` to a function that enables tab |
| 1554 | completion and history saving (in :file:`~/.python-history`) if the platform |
| 1555 | supports :mod:`readline`. If you do not want this (new) behavior, you can |
| 1556 | override it in :envvar:`PYTHONSTARTUP`, :mod:`sitecustomize`, or |
| 1557 | :mod:`usercustomize` by deleting this attribute from :mod:`sys` (or setting it |
| 1558 | to some other callable). (Contributed by Éric Araujo and Antoine Pitrou in |
| 1559 | :issue:`5845`.) |
| 1560 | |
| 1561 | |
| 1562 | tarfile |
| 1563 | ------- |
| 1564 | |
| 1565 | The :mod:`tarfile` module now supports a simple :ref:`tarfile-commandline` when |
| 1566 | called as a script directly or via ``-m``. This can be used to create and |
| 1567 | extract tarfile archives. (Contributed by Berker Peksag in :issue:`13477`.) |
| 1568 | |
| 1569 | |
| 1570 | textwrap |
| 1571 | -------- |
| 1572 | |
| 1573 | The :class:`~textwrap.TextWrapper` class has two new attributes/constructor |
| 1574 | arguments: :attr:`~textwrap.TextWrapper.max_lines`, which limits the number of |
| 1575 | lines in the output, and :attr:`~textwrap.TextWrapper.placeholder`, which is a |
| 1576 | string that will appear at the end of the output if it has been truncated |
| 1577 | because of *max_lines*. Building on these capabilities, a new convenience |
| 1578 | function :func:`~textwrap.shorten` collapses all of the whitespace in the input |
| 1579 | to single spaces and produces a single line of a given *width* that ends with |
| 1580 | the *placeholder* (by default, ``[...]``). (Contributed by Antoine Pitrou and |
| 1581 | Serhiy Storchaka in :issue:`18585` and :issue:`18725`.) |
| 1582 | |
| 1583 | |
| 1584 | threading |
| 1585 | --------- |
| 1586 | |
| 1587 | The :class:`~threading.Thread` object representing the main thread can be |
| 1588 | obtained from the new :func:`~threading.main_thread` function. In normal |
| 1589 | conditions this will be the thread from which the Python interpreter was |
| 1590 | started. (Contributed by Andrew Svetlov in :issue:`18882`.) |
| 1591 | |
R David Murray | d17aba7 | 2013-12-24 14:46:23 -0500 | [diff] [blame] | 1592 | |
Andrew Kuchling | 173a157 | 2013-09-15 18:15:56 -0400 | [diff] [blame] | 1593 | traceback |
| 1594 | --------- |
| 1595 | |
| 1596 | A new :func:`traceback.clear_frames` function takes a traceback object |
| 1597 | and clears the local variables in all of the frames it references, |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1598 | reducing the amount of memory consumed. (Contributed by Andrew Kuchling in |
| 1599 | :issue:`1565525`). |
| 1600 | |
| 1601 | |
| 1602 | types |
| 1603 | ----- |
| 1604 | |
| 1605 | A new :func:`~types.DynamicClassAttribute` descriptor provides a way to define |
| 1606 | an attribute that acts normally when looked up through an instance object, but |
| 1607 | which is routed to the *class* ``__getattr__`` when looked up through the |
| 1608 | class. This allows one to have properties active on a class, and have virtual |
| 1609 | attributes on the class with the same name (see :mod:`Enum` for an example). |
| 1610 | (Contributed by Ethan Furman in :issue:`19030`.) |
Andrew Kuchling | 173a157 | 2013-09-15 18:15:56 -0400 | [diff] [blame] | 1611 | |
| 1612 | |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1613 | urllib |
| 1614 | ------ |
| 1615 | |
R David Murray | 473f45b | 2013-12-27 17:01:16 -0500 | [diff] [blame] | 1616 | :mod:`urllib.request` now supports ``data:`` URLs via the |
| 1617 | :class:`~urllib.request.DataHandler` class. (Contributed by Mathias Panzenböck |
| 1618 | in :issue:`16423`.) |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1619 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1620 | The http method that will be used by a :class:`~urllib.request.Request` class |
| 1621 | can now be specified by setting a :class:`~urllib.request.Request.method` |
| 1622 | class attribute on the subclass. (Contributed by Jason R Coombs in |
| 1623 | :issue:`18978`.) |
| 1624 | |
| 1625 | :class:`~urllib.request.Request` objects are now reusable: if the |
| 1626 | :attr:`~urllib.request.Request.full_url` or :attr:`~urllib.request.Request.data` |
| 1627 | attributes are modified, all relevant internal properties are updated. This |
| 1628 | means, for example, that it is now possible to use the same |
| 1629 | :class:`~urllib.request.Request` object in more than one |
| 1630 | :meth:`.OpenerDirector.open` call with different *data* arguments, or to |
| 1631 | modify a :class:`~urllib.request.Request`\ 's ``url`` rather than recomputing it |
| 1632 | from scratch. There is also a new |
| 1633 | :meth:`~urllib.request.Request.remove_header` method that can be used to remove |
| 1634 | headers from a :class:`~urllib.request.Request`. (Contributed by Alexey |
| 1635 | Kachayev in :issue:`16464`, Daniel Wozniak in :issue:`17485`, and Damien Brecht |
| 1636 | and Senthil Kumaran in :issue:`17272`.) |
| 1637 | |
| 1638 | :class:`~urllib.error.HTTPError` objects now have a |
| 1639 | :attr:`~urllib.error.HTTPError.headers` attribute that provides access to the |
| 1640 | HTTP response headers associated with the error. (Contributed by |
| 1641 | Berker Peksag in :issue:`15701`.) |
| 1642 | |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1643 | |
| 1644 | unittest |
| 1645 | -------- |
| 1646 | |
R David Murray | 57fcf76 | 2014-01-03 23:31:54 -0500 | [diff] [blame] | 1647 | The :class:`~unittest.TestCase` class has a new method, |
| 1648 | :meth:`~unittest.TestCase.subTest`, that produces a context manager whose |
| 1649 | :keyword:`with` block becomes a "sub-test". This context manager allows a test |
| 1650 | method to dynamically generate subtests by, say, calling the ``subTest`` |
| 1651 | context manager inside a loop. A single test method can thereby produce an |
| 1652 | indefinite number of separately-identified and separately-counted tests, all of |
| 1653 | which will run even if one or more of them fail. For example:: |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1654 | |
R David Murray | 57fcf76 | 2014-01-03 23:31:54 -0500 | [diff] [blame] | 1655 | class NumbersTest(unittest.TestCase): |
| 1656 | def test_even(self): |
| 1657 | for i in range(6): |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1658 | with self.subTest(i=i): |
R David Murray | 57fcf76 | 2014-01-03 23:31:54 -0500 | [diff] [blame] | 1659 | self.assertEqual(i % 2, 0) |
| 1660 | |
| 1661 | will result in six subtests, each identified in the unittest verbose output |
| 1662 | with a label consisting of the variable name ``i`` and a particular value for |
| 1663 | that variable (``i=0``, ``i=1``, etc). See :ref:`subtests` for the full |
| 1664 | version of this example. (Contributed by Antoine Pitrou in :issue:`16997`.) |
| 1665 | |
| 1666 | :func:`unittest.main` now accepts an iterable of test names for |
R David Murray | 9025f1c | 2014-01-02 13:44:18 -0500 | [diff] [blame] | 1667 | *defaultTest*, where previously it only accepted a single test name as a |
| 1668 | string. (Contributed by Jyrki Pulliainen in :issue:`15132`.) |
| 1669 | |
R David Murray | 42fa110 | 2014-01-03 13:03:36 -0500 | [diff] [blame] | 1670 | If :class:`~unittest.SkipTest` is raised during test discovery (that is, at the |
| 1671 | module level in the test file), it is now reported as a skip instead of an |
| 1672 | error. (Contributed by Zach Ware in :issue:`16935`.) |
| 1673 | |
R David Murray | db085f5 | 2014-01-03 15:46:24 -0500 | [diff] [blame] | 1674 | :meth:`~unittest.TestLoader.discover` now sorts the discovered files to provide |
| 1675 | consistent test ordering. (Contributed by Martin Melin and Jeff Ramnani in |
| 1676 | :issue:`16709`.) |
| 1677 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1678 | :class:`~unittest.TestSuite` now drops references to tests as soon as the test |
| 1679 | has been run, if the test is successful. On Python interpreters that do |
| 1680 | garbage collection, this allows the tests to be garbage collected if nothing |
| 1681 | else is holding a reference to the test. It is possible to override this |
| 1682 | behavior by creating a :class:`~unittest.TestSuite` subclass that defines a |
| 1683 | custom ``_removeTestAtIndex`` method. (Contributed by Tom Wardill, Matt |
| 1684 | McClure, and Andrew Svetlov in :issue:`11798`.) |
| 1685 | |
| 1686 | A new test assertion context-manager, :meth:`~unittest.TestCase.assertLogs`, |
| 1687 | will ensure that a given block of code emits a log message using the |
| 1688 | :mod:`logging` module. By default the message can come from any logger and |
| 1689 | have a priority of ``INFO`` or higher, but both the logger name and an |
| 1690 | alternative minimum logging level may be specified. The object returned by the |
| 1691 | context manager can be queried for the :class:`~logging.LogRecord`\ s and/or |
| 1692 | formatted messages that were logged. (Contributed by Antoine Pitrou in |
| 1693 | :issue:`18937`.) |
| 1694 | |
| 1695 | Test discovery now works with namespace packages (Contributed by Claudiu Popa |
| 1696 | in :issue:`17457`.) |
| 1697 | |
| 1698 | :mod:`unittest.mock` objects now inspect their specification signatures when |
| 1699 | matching calls, which means an argument can now be matched by either position |
| 1700 | or name, instead of only by position. (Contributed by Antoine Pitrou in |
| 1701 | :issue:`17015`.) |
| 1702 | |
| 1703 | :func:`~mock.mock_open` objects now have ``readline`` and ``readlines`` |
| 1704 | methods. (Contributed by Toshio Kuratomi in :issue:`17467`.) |
| 1705 | |
R David Murray | 8e37d5d | 2013-04-13 14:49:48 -0400 | [diff] [blame] | 1706 | |
R David Murray | 575fb31 | 2013-12-25 23:21:03 -0500 | [diff] [blame] | 1707 | venv |
| 1708 | ---- |
| 1709 | |
| 1710 | :mod:`venv` now includes activation scripts for the ``csh`` and ``fish`` |
| 1711 | shells (Contributed by Andrew Svetlov in :issue:`15417`.) |
| 1712 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1713 | :class:`~venv.EnvBuilder` and the :func:`~venv.create` convenience function |
| 1714 | take a new keyword argument *with_pip*, which defaults to ``False``, that |
| 1715 | controls whether or not :class:`~venv.EnvBuilder` ensures that ``pip`` is |
| 1716 | installed in the virtual environment. (Contributed by Nick Coghlan in |
| 1717 | :issue:`19552` as part of the :pep:`453` implementation.) |
| 1718 | |
R David Murray | 575fb31 | 2013-12-25 23:21:03 -0500 | [diff] [blame] | 1719 | |
R David Murray | 671cd32 | 2013-04-10 12:31:43 -0400 | [diff] [blame] | 1720 | wave |
| 1721 | ---- |
| 1722 | |
| 1723 | The :meth:`~wave.getparams` method now returns a namedtuple rather than a |
| 1724 | plain tuple. (Contributed by Claudiu Popa in :issue:`17487`.) |
| 1725 | |
R David Murray | c91d5ee | 2013-07-31 13:46:08 -0400 | [diff] [blame] | 1726 | :meth:`wave.open` now supports the context manager protocol. (Contributed |
| 1727 | by Claudiu Popa in :issue:`17616`.) |
| 1728 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1729 | :mod:`wave` can now :ref:`write output to unseekable files |
| 1730 | <wave-write-objects>`. (Contributed by David Jones, Guilherme Polo, and Serhiy |
| 1731 | Storchaka in :issue:`5202`.) |
| 1732 | |
| 1733 | The :meth:`~wave.Wave_write.writeframesraw` and |
| 1734 | :meth:`~wave.Wave_write.writeframes` methods now accept any :term:`bytes-like |
| 1735 | object`. (Contributed by Serhiy Storchaka in :issue:`8311`.) |
| 1736 | |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1737 | |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1738 | weakref |
| 1739 | ------- |
| 1740 | |
| 1741 | New :class:`~weakref.WeakMethod` class simulates weak references to bound |
Nick Coghlan | be57ab8 | 2013-09-22 21:26:30 +1000 | [diff] [blame] | 1742 | methods. (Contributed by Antoine Pitrou in :issue:`14631`.) |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1743 | |
Nick Coghlan | be57ab8 | 2013-09-22 21:26:30 +1000 | [diff] [blame] | 1744 | New :class:`~weakref.finalize` class makes it possible to register a callback |
| 1745 | to be invoked when an object is garbage collected, without needing to |
| 1746 | carefully manage the lifecycle of the weak reference itself. (Contributed by |
| 1747 | Richard Oudkerk in :issue:`15528`) |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1748 | |
R David Murray | a101bdb | 2014-01-06 16:32:05 -0500 | [diff] [blame] | 1749 | The callback, if any, associated with a :class:`~weakref.ref` is now |
| 1750 | exposed via the :attr:`~weakref.ref.__callback__` attribute. (Contributed |
| 1751 | by Mark Dickinson in :issue:`17643`.) |
| 1752 | |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1753 | |
| 1754 | xml.etree |
| 1755 | --------- |
| 1756 | |
R David Murray | 410d320 | 2014-01-04 23:52:50 -0500 | [diff] [blame] | 1757 | A new parser, :class:`~xml.etree.ElementTree.XMLPullParser`, allows a |
| 1758 | non-blocking applications to parse XML documents. An example can be |
| 1759 | seen at :ref:`elementtree-pull-parsing`. (Contributed by Antoine |
| 1760 | Pitrou in :issue:`17741`.) |
Antoine Pitrou | f89aa9a | 2013-08-12 20:46:47 +0200 | [diff] [blame] | 1761 | |
R David Murray | 575fb31 | 2013-12-25 23:21:03 -0500 | [diff] [blame] | 1762 | The :mod:`xml.etree.ElementTree` :func:`~xml.etree.ElementTree.tostring` and |
| 1763 | :func:`~xml.etree.ElementTree.tostringlist` functions, and the |
| 1764 | :class:`~xml.etree.ElementTree.ElementTree` |
| 1765 | :meth:`~xml.etree.ElementTree.ElementTree.write` method, now have a |
| 1766 | *short_empty_elements* :ref:`keyword-only parameter <keyword-only_parameter>` |
| 1767 | providing control over whether elements with no content are written in |
| 1768 | abbreviated (``<tag />``) or expanded (``<tag></tag>``) form. (Contributed by |
| 1769 | Ariel Poliak and Serhiy Storchaka in :issue:`14377`.) |
| 1770 | |
Christian Tismer | 59202e5 | 2013-10-21 03:59:23 +0200 | [diff] [blame] | 1771 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1772 | zipfile |
| 1773 | ------- |
Christian Tismer | 59202e5 | 2013-10-21 03:59:23 +0200 | [diff] [blame] | 1774 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1775 | The :meth:`~zipfile.PyZipFile.writepy` method of the |
| 1776 | :class:`~zipfile.PyZipFile` class has a new *filterfunc* option that can be |
| 1777 | used to control which directories and files are added to the archive. For |
| 1778 | example, this could be used to exclude test files from the archive. |
Christian Tismer | 59202e5 | 2013-10-21 03:59:23 +0200 | [diff] [blame] | 1779 | (Contributed by Christian Tismer in :issue:`19274`.) |
| 1780 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1781 | The *allowZip64* parameter to :class:`~zipfile.ZipFile` and |
| 1782 | :class:`~zipfile.PyZipfile` is now ``True`` by default. (Contributed by |
| 1783 | William Mallard in :issue:`17201`.) |
| 1784 | |
Christian Tismer | 59202e5 | 2013-10-21 03:59:23 +0200 | [diff] [blame] | 1785 | |
R David Murray | e608255 | 2014-01-03 16:15:45 -0500 | [diff] [blame] | 1786 | |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1787 | CPython Implementation Changes |
| 1788 | ============================== |
| 1789 | |
| 1790 | |
R David Murray | c16dfe1 | 2013-12-21 12:32:10 -0500 | [diff] [blame] | 1791 | .. _whatsnew-pep-445: |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1792 | |
R David Murray | e7cf678 | 2013-12-24 14:51:25 -0500 | [diff] [blame] | 1793 | PEP 445: Customization of CPython Memory Allocators |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1794 | --------------------------------------------------- |
| 1795 | |
| 1796 | :pep:`445` adds new C level interfaces to customize memory allocation in |
| 1797 | the CPython interpreter. |
| 1798 | |
| 1799 | .. seealso:: |
| 1800 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 1801 | :pep:`445` -- Add new APIs to customize Python memory allocators |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1802 | PEP written and implemented by Victor Stinner. |
| 1803 | |
| 1804 | |
R David Murray | c16dfe1 | 2013-12-21 12:32:10 -0500 | [diff] [blame] | 1805 | .. _whatsnew-pep-442: |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1806 | |
R David Murray | e7cf678 | 2013-12-24 14:51:25 -0500 | [diff] [blame] | 1807 | PEP 442: Safe Object Finalization |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1808 | --------------------------------- |
| 1809 | |
| 1810 | :pep:`442` removes the current limitations and quirks of object finalization |
| 1811 | in CPython. With it, objects with :meth:`__del__` methods, as well as |
| 1812 | generators with :keyword:`finally` clauses, can be finalized when they are |
| 1813 | part of a reference cycle. |
| 1814 | |
| 1815 | As part of this change, module globals are no longer forcibly set to |
| 1816 | :const:`None` during interpreter shutdown in most cases, instead relying |
R David Murray | ca79461 | 2013-12-22 14:05:11 -0500 | [diff] [blame] | 1817 | on the normal operation of the cyclic garbage collector. This avoids a |
| 1818 | whole class of interpreter-shutdown-time errors, usually involving |
| 1819 | ``__del__`` methods, that have plagued Python since the cyclic GC |
| 1820 | was first introduced. |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1821 | |
| 1822 | .. seealso:: |
| 1823 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 1824 | :pep:`442` -- Safe object finalization |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1825 | PEP written and implemented by Antoine Pitrou. |
| 1826 | |
| 1827 | |
R David Murray | c16dfe1 | 2013-12-21 12:32:10 -0500 | [diff] [blame] | 1828 | .. _whatsnew-pep-456: |
| 1829 | |
| 1830 | PEP 456: Secure and Interchangeable Hash Algorithm |
| 1831 | -------------------------------------------------- |
| 1832 | |
| 1833 | :pep:`456` follows up on earlier security fix work done on Python's hash |
| 1834 | algorithm to address certain DOS attacks to which public facing APIs backed by |
| 1835 | dictionary lookups may be subject. (See :issue:`14621` for the start of the |
| 1836 | current round of improvements.) The PEP unifies CPython's hash code to make it |
| 1837 | easier for a packager to substitute a different hash algorithm, and switches |
| 1838 | Python's default implementation to a SipHash implementation on platforms that |
| 1839 | have a 64 bit data type. Any performance differences in comparison with the |
| 1840 | older FNV algorithm are trivial. |
| 1841 | |
| 1842 | The PEP adds additional fields to the :func:`sys.hash_info` struct sequence to |
| 1843 | describe the hash algorithm in use by the currently executing binary. Otherwise, |
| 1844 | the PEP does not alter any existing CPython APIs. |
| 1845 | |
| 1846 | |
R David Murray | 6dd1830 | 2013-12-24 12:23:56 -0500 | [diff] [blame] | 1847 | .. _whatsnew-pep-436: |
| 1848 | |
| 1849 | PEP 436: Argument Clinic |
| 1850 | ------------------------ |
| 1851 | |
| 1852 | "Argument Clinic" (:pep:`436`) is now part of the CPython build process |
| 1853 | and can be used to simplify the process of defining and maintaining |
| 1854 | accurate signatures for builtins and standard library extension modules |
| 1855 | implemented in C. |
| 1856 | |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 1857 | Some standard library extension modules have been converted to use Argument |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1858 | Clinic in Python 3.4, and :mod:`pydoc` and :mod:`inspect` have been updated |
| 1859 | accordingly. |
| 1860 | |
| 1861 | It is expected that signature metadata for programmatic introspection will |
| 1862 | be added to additional callables implemented in C as part of Python 3.4 |
| 1863 | maintenance releases. |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 1864 | |
R David Murray | 6dd1830 | 2013-12-24 12:23:56 -0500 | [diff] [blame] | 1865 | .. note:: |
| 1866 | The Argument Clinic PEP is not fully up to date with the state of the |
| 1867 | implementation. This has been deemed acceptable by the release manager |
| 1868 | and core development team in this case, as Argument Clinic will not |
| 1869 | be made available as a public API for third party use in Python 3.4. |
| 1870 | |
| 1871 | .. seealso:: |
| 1872 | |
R David Murray | 061efb1 | 2013-12-24 12:35:59 -0500 | [diff] [blame] | 1873 | :pep:`436` -- The Argument Clinic DSL |
R David Murray | 6dd1830 | 2013-12-24 12:23:56 -0500 | [diff] [blame] | 1874 | PEP written and implemented by Larry Hastings. |
| 1875 | |
| 1876 | |
R David Murray | e7cf678 | 2013-12-24 14:51:25 -0500 | [diff] [blame] | 1877 | Other Build and C API Changes |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 1878 | ----------------------------- |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 1879 | |
Nick Coghlan | aa029da | 2014-02-09 10:10:24 +1000 | [diff] [blame] | 1880 | * The new :c:func:`PyType_GetSlot` function has been added to the stable ABI, |
| 1881 | allowing retrieval of function pointers from named type slots when using |
| 1882 | the limited API. (Contributed by Martin von Löwis in :issue:`17162`) |
| 1883 | |
Nick Coghlan | 7d270ee | 2013-10-17 22:35:35 +1000 | [diff] [blame] | 1884 | * The new :c:func:`Py_SetStandardStreamEncoding` pre-initialization API |
| 1885 | allows applications embedding the CPython interpreter to reliably force |
| 1886 | a particular encoding and error handler for the standard streams |
| 1887 | (Contributed by Bastien Montagne and Nick Coghlan in :issue:`16129`) |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 1888 | |
Nick Coghlan | 0acceb7 | 2013-10-20 13:22:21 +1000 | [diff] [blame] | 1889 | * Most Python C APIs that don't mutate string arguments are now correctly |
| 1890 | marked as accepting ``const char *`` rather than ``char *`` (Contributed |
| 1891 | by Serhiy Storchaka in :issue:`1772673`). |
| 1892 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1893 | * A new shell version of ``python-config`` can be used even when a python |
R David Murray | d91ba20 | 2013-12-24 12:13:44 -0500 | [diff] [blame] | 1894 | interpreter is not available (for example, in cross compilation scenarios). |
| 1895 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1896 | * :c:func:`PyUnicode_FromFormat` now supports width and precision |
| 1897 | specifications for ``%s``, ``%A``, ``%U``, ``%V``, ``%S``, and ``%R``. |
| 1898 | (Contributed by Ysj Ray and Victor Stinner in :issue:`7330`.) |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 1899 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1900 | * New function :c:func:`PyStructSequence_InitType2` supplements the |
| 1901 | existing :c:func:`PyStructSequence_InitType` function. The difference |
| 1902 | is that it returns ``0`` on success and ``-1`` on failure. |
| 1903 | |
| 1904 | * The CPython source can now be compiled using the address sanity checking |
| 1905 | features of recent versions of GCC and clang: the false alarms in the small |
| 1906 | object allocator have been silenced. (Contributed by Dhiru Kholia in |
| 1907 | :issue:`18596`.) |
| 1908 | |
| 1909 | * The Windows build now uses `Address Space Layout Randomization |
| 1910 | <http://en.wikipedia.org/wiki/ASLR>`_ and `Data Execution Prevention |
| 1911 | <http://en.wikipedia.org/wiki/Data_Execution_Prevention>`_. (Contributed by |
| 1912 | Christian Heimes in :issue:`16632`.) |
| 1913 | |
| 1914 | * New function :c:func:`PyObject_LengthHint` is the C API equivalent |
| 1915 | of :func:`operator.length_hint`. (Contributed by Armin Ronacher in |
| 1916 | :issue:`16148`.) |
| 1917 | |
| 1918 | |
| 1919 | .. _other-improvements-3.4: |
R David Murray | e608255 | 2014-01-03 16:15:45 -0500 | [diff] [blame] | 1920 | |
R David Murray | e7cf678 | 2013-12-24 14:51:25 -0500 | [diff] [blame] | 1921 | Other Improvements |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1922 | ------------------ |
R David Murray | bcaaecf | 2013-12-23 21:23:36 -0500 | [diff] [blame] | 1923 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1924 | .. _whatsnew-isolated-mode: |
| 1925 | |
| 1926 | * The :ref:`python <using-on-cmdline>` command has a new :ref:`option |
| 1927 | <using-on-misc-options>`, ``-I``, which causes it to run in "isolated mode", |
| 1928 | which means that :data:`sys.path` contains neither the script's directory nor |
| 1929 | the user's ``site-packages`` directory, and all :envvar:`PYTHON*` environment |
| 1930 | variables are ignored (it implies both ``-s`` and ``-E``). Other |
| 1931 | restrictions may also be applied in the future, with the goal being to |
| 1932 | isolate the execution of a script from the user's environment. This is |
| 1933 | appropriate, for example, when Python is used to run a system script. On |
| 1934 | most POSIX systems it can and should be used in the ``#!`` line of system |
| 1935 | scripts. (Contributed by Christian Heimes in :issue:`16499`.) |
| 1936 | |
| 1937 | * Tab-completion is now enabled by default in the interactive interpreter |
| 1938 | on systems that support :mod:`readline`. History is also enabled by default, |
| 1939 | and is written to (and read from) the file :file:`~/.python-history`. |
R David Murray | bcaaecf | 2013-12-23 21:23:36 -0500 | [diff] [blame] | 1940 | (Contributed by Antoine Pitrou and Éric Araujo in :issue:`5845`.) |
| 1941 | |
| 1942 | * Invoking the Python interpreter with ``--version`` now outputs the version to |
| 1943 | standard output instead of standard error (:issue:`18338`). Similar changes |
| 1944 | were made to :mod:`argparse` (:issue:`18920`) and other modules that have |
| 1945 | script-like invocation capabilities (:issue:`18922`). |
| 1946 | |
R David Murray | 72420ff | 2013-12-24 10:46:44 -0500 | [diff] [blame] | 1947 | * The CPython Windows installer now adds ``.py`` to the :envvar:`PATHEXT` |
| 1948 | variable when extensions are registered, allowing users to run a python |
| 1949 | script at the windows command prompt by just typing its name without the |
| 1950 | ``.py`` extension. (Contributed by Paul Moore in :issue:`18569`.) |
| 1951 | |
R David Murray | d17aba7 | 2013-12-24 14:46:23 -0500 | [diff] [blame] | 1952 | * A new ``make`` target `coverage-report |
| 1953 | <http://docs.python.org/devguide/coverage.html#measuring-coverage-of-c-code-with-gcov-and-lcov>`_ |
| 1954 | will build python, run the test suite, and generate an HTML coverage report |
| 1955 | for the C codebase using ``gcov`` and `lcov |
| 1956 | <http://ltp.sourceforge.net/coverage/lcov.php>`_. |
| 1957 | |
| 1958 | * The ``-R`` option to the :ref:`python regression test suite <regrtest>` now |
| 1959 | also checks for memory allocation leaks, using |
| 1960 | :func:`sys.getallocatedblocks()`. (Contributed by Antoine Pitrou in |
| 1961 | :issue:`13390`). |
| 1962 | |
R David Murray | 5147e00 | 2014-02-02 12:19:57 -0500 | [diff] [blame] | 1963 | * ``python -m`` now works with namespace packages. |
| 1964 | |
R David Murray | a56d4e8 | 2014-02-02 12:50:48 -0500 | [diff] [blame] | 1965 | * The :mod:`stat` module is now implemented in C, which means it gets the |
| 1966 | values for its constants from the C header files, instead of having the |
| 1967 | values hard-coded in the python module as was previously the case. |
| 1968 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 1969 | * Loading multiple python modules from a single OS module (``.so``, ``.dll``) |
| 1970 | now works correctly (previously it silently returned the first python |
| 1971 | module in the file). (Contributed by Václav Šmilauer in :issue:`16421`.) |
| 1972 | |
| 1973 | * A new opcode, :opcode:`LOAD_CLASSDEREF`, has been added to fix a bug in the |
| 1974 | loading of free variables in class bodies that could be triggered by certain |
| 1975 | uses of :ref:`__prepare__ <prepare>`. (Contributed by Benjamin Peterson in |
| 1976 | :issue:`17853`.) |
| 1977 | |
| 1978 | * A number of MemoryError-related crashes were identified and fixed by Victor |
| 1979 | Stinner using his :pep:`445`-based ``pyfailmalloc`` tool (:issue:`18408`, |
| 1980 | :issue:`18520`). |
| 1981 | |
| 1982 | * The :ref:`pyvenv <scripts-pyvenv>` command now accepts a ``--copies`` option |
| 1983 | to use copies rather than symlinks even on systems where symlinks are the |
| 1984 | default. (Contributed by Vinay Sajip in :issue:`18807`.) |
| 1985 | |
| 1986 | * The :ref:`pyvenv <scripts-pyvenv>` command also accepts a ``--without-pip`` |
| 1987 | option to suppress the otherwise-automatic bootstrapping of pip into |
| 1988 | the virtual environment. (Contributed by Nick Coghlan in :issue:`19552` |
| 1989 | as part of the :pep:`453` implementation.) |
| 1990 | |
| 1991 | * The encoding name is now optional in the value set for the |
| 1992 | :envvar:`PYTHONIOENCODING` environment variable. This makes it possible to |
| 1993 | set just the error handler, without changing the default encoding. |
| 1994 | (Contributed by Serhiy Storchaka in :issue:`18818`.) |
| 1995 | |
| 1996 | * The :mod:`bz2`, :mod:`lzma`, and :mod:`gzip` module ``open`` functions now |
| 1997 | support ``x`` (exclusive creation) mode. (Contributed by Tim Heaney and |
| 1998 | Vajrasky Kok in :issue:`19201`, :issue:`19222`, and :issue:`19223`.) |
R David Murray | bcaaecf | 2013-12-23 21:23:36 -0500 | [diff] [blame] | 1999 | |
R David Murray | e608255 | 2014-01-03 16:15:45 -0500 | [diff] [blame] | 2000 | |
R David Murray | d74d09a | 2013-12-24 15:33:02 -0500 | [diff] [blame] | 2001 | Significant Optimizations |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2002 | ------------------------- |
R David Murray | bcaaecf | 2013-12-23 21:23:36 -0500 | [diff] [blame] | 2003 | |
R David Murray | 4908f4a | 2014-01-04 18:07:20 -0500 | [diff] [blame] | 2004 | * The UTF-32 decoder is now 3x to 4x faster. (Contributed by Serhiy Storchaka |
| 2005 | in :issue:`14625`.) |
R David Murray | bcaaecf | 2013-12-23 21:23:36 -0500 | [diff] [blame] | 2006 | |
| 2007 | * The cost of hash collisions for sets is now reduced. Each hash table |
| 2008 | probe now checks a series of consecutive, adjacent key/hash pairs before |
| 2009 | continuing to make random probes through the hash table. This exploits |
| 2010 | cache locality to make collision resolution less expensive. |
R David Murray | bcaaecf | 2013-12-23 21:23:36 -0500 | [diff] [blame] | 2011 | The collision resolution scheme can be described as a hybrid of linear |
| 2012 | probing and open addressing. The number of additional linear probes |
| 2013 | defaults to nine. This can be changed at compile-time by defining |
| 2014 | LINEAR_PROBES to be any value. Set LINEAR_PROBES=0 to turn-off |
R David Murray | 5917172 | 2014-01-03 15:52:22 -0500 | [diff] [blame] | 2015 | linear probing entirely. (Contributed by Raymond Hettinger in |
| 2016 | :issue:`18771`.) |
R David Murray | bcaaecf | 2013-12-23 21:23:36 -0500 | [diff] [blame] | 2017 | |
| 2018 | * The interpreter starts about 30% faster. A couple of measures lead to the |
| 2019 | speedup. The interpreter loads fewer modules on startup, e.g. the :mod:`re`, |
| 2020 | :mod:`collections` and :mod:`locale` modules and their dependencies are no |
| 2021 | longer imported by default. The marshal module has been improved to load |
R David Murray | 5917172 | 2014-01-03 15:52:22 -0500 | [diff] [blame] | 2022 | compiled Python code faster. (Contributed by Antoine Pitrou, Christian |
| 2023 | Heimes and Victor Stinner in :issue:`19219`, :issue:`19218`, :issue:`19209`, |
| 2024 | :issue:`19205` and :issue:`9548`) |
R David Murray | bcaaecf | 2013-12-23 21:23:36 -0500 | [diff] [blame] | 2025 | |
R David Murray | 6e39015 | 2013-12-24 22:28:04 -0500 | [diff] [blame] | 2026 | * :class:`bz2.BZ2File` is now as fast or faster than the Python2 version for |
| 2027 | most cases. :class:`lzma.LZMAFile` has also been optimized. (Contributed by |
| 2028 | Serhiy Storchaka and Nadeem Vawda in :issue:`16034`.) |
| 2029 | |
R David Murray | 8b2d682 | 2013-12-31 15:06:05 -0500 | [diff] [blame] | 2030 | * :func:`random.getrandbits` is 20%-40% faster for small integers (the most |
| 2031 | common use case). (Contributed by Serhiy Storchaka in :issue:`16674`). |
| 2032 | |
R David Murray | b231b2b | 2014-01-04 17:11:23 -0500 | [diff] [blame] | 2033 | * By taking advantage of the new storage format for strings, pickling of |
| 2034 | strings is now significantly faster. (Contributed by Victor Stinner and |
| 2035 | Antoine Pitrou in :issue:`15596`.) |
| 2036 | |
R David Murray | 66bf12a | 2014-01-08 17:21:22 -0500 | [diff] [blame] | 2037 | * A performance issue in :meth:`io.FileIO.readall` has been solved. This |
| 2038 | particularly affects Windows, and significantly speeds up the case of piping |
| 2039 | significant amounts of data through :mod:`subprocess`. (Contributed |
| 2040 | by Richard Oudkerk in :issue:`15758`.) |
| 2041 | |
R David Murray | bf0ab83 | 2014-02-03 01:14:03 -0500 | [diff] [blame] | 2042 | * :func:`html.escape` is now 10x faster. (Contributed by Matt Bryant in |
| 2043 | :issue:`18020`.) |
R David Murray | bcaaecf | 2013-12-23 21:23:36 -0500 | [diff] [blame] | 2044 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2045 | * On Windows, the native ``VirtualAlloc`` is now used instead of the CRT |
| 2046 | ``malloc`` in ``obmalloc``. Artificial benchmarks show about a 3% memory |
| 2047 | savings. |
| 2048 | |
| 2049 | * :func:`os.urandom` now uses a lazily-opened persistent file descriptor |
| 2050 | so as to avoid using many file descriptors when run in parallel from |
| 2051 | multiple threads. (Contributed by Antoine Pitrou in :issue:`18756`.) |
| 2052 | |
| 2053 | |
| 2054 | .. _deprecated-3.4: |
R David Murray | e608255 | 2014-01-03 16:15:45 -0500 | [diff] [blame] | 2055 | |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 2056 | Deprecated |
| 2057 | ========== |
| 2058 | |
R David Murray | d74d09a | 2013-12-24 15:33:02 -0500 | [diff] [blame] | 2059 | This section covers various APIs and other features that have been deprecated |
| 2060 | in Python 3.4, and will be removed in Python 3.5 or later. In most (but not |
| 2061 | all) cases, using the deprecated APIs will produce a :exc:`DeprecationWarning` |
| 2062 | when the interpreter is run with deprecation warnings enabled (for example, by |
| 2063 | using ``-Wd``). |
| 2064 | |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 2065 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2066 | Deprecations in the Python API |
| 2067 | ------------------------------ |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 2068 | |
R David Murray | b79b785 | 2014-02-22 14:28:46 -0500 | [diff] [blame] | 2069 | * As mentioned in :ref:`whatsnew-pep-451`, a number of :mod:`importilb` |
| 2070 | methods and functions are deprecated: :meth:`importlib.find_loader` is |
| 2071 | replaced by :func:`importlib.util.find_spec`; |
| 2072 | :meth:`importlib.machinery.PathFinder.find_module` is replaced by |
| 2073 | :meth:`importlib.machinery.PathFinder.find_spec`; |
| 2074 | :meth:`importlib.abc.MetaPathFinder.find_module` is replaced by |
| 2075 | :meth:`importlib.abc.MetaPathFinder.find_spec`; |
| 2076 | :meth:`importlib.abc.PathEntryFinder.find_loader` and |
| 2077 | :meth:`~importlib.abc.PathEntryFinder.find_module` are replaced by |
| 2078 | :meth:`importlib.abc.PathEntryFinder.find_spec`; all of the ``xxxLoader`` ABC |
| 2079 | ``load_module`` methods (:meth:`importlib.abc.Loader.load_module`, |
| 2080 | :meth:`importlib.abc.InspectLoader.load_module`, |
| 2081 | :meth:`importlib.abc.FileLoader.load_module`, |
| 2082 | :meth:`importlib.abc.SourceLoader.load_module`) should no longer be |
| 2083 | implemented, instead loaders should implement an |
| 2084 | ``exec_module`` method |
| 2085 | (:meth:`importlib.abc.Loader.exec_module`, |
| 2086 | :meth:`importlib.abc.InspectLoader.exec_module` |
| 2087 | :meth:`importlib.abc.SourceLoader.exec_module`) and let the import system |
| 2088 | take care of the rest; and |
| 2089 | :meth:`importlib.abc.Loader.module_repr`, |
| 2090 | :meth:`importlib.util.module_for_loader`, :meth:`importlib.util.set_loader`, |
| 2091 | and :meth:`importlib.util.set_package` are no longer needed because their |
| 2092 | functions are now handled automatically by the import system. |
Brett Cannon | 82b3d6a | 2013-06-14 22:37:11 -0400 | [diff] [blame] | 2093 | |
Brett Cannon | e4f41de | 2013-06-16 13:13:40 -0400 | [diff] [blame] | 2094 | * The :mod:`imp` module is pending deprecation. To keep compatibility with |
| 2095 | Python 2/3 code bases, the module's removal is currently not scheduled. |
| 2096 | |
Brett Cannon | 1448ecf | 2013-10-04 11:38:59 -0400 | [diff] [blame] | 2097 | * The :mod:`formatter` module is pending deprecation and is slated for removal |
| 2098 | in Python 3.6. |
| 2099 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2100 | * ``MD5`` as the default *digestmod* for the :func:`hmac.new` function is |
| 2101 | deprecated. Python 3.6 will require an explicit digest name or constructor as |
| 2102 | *digestmod* argument. |
Christian Heimes | 634919a | 2013-11-20 17:23:06 +0100 | [diff] [blame] | 2103 | |
R David Murray | 9025f1c | 2014-01-02 13:44:18 -0500 | [diff] [blame] | 2104 | * The internal ``Netrc`` class in the :mod:`ftplib` module has been documented |
| 2105 | as deprecated in its docstring for quite some time. It now emits a |
| 2106 | :exc:`DeprecationWarning` and will be removed completely in Python 3.5. |
| 2107 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2108 | * The undocumented *endtime* argument to :meth:`subprocess.Popen.wait` should |
| 2109 | not have been exposed and is hopefully not in use; it is deprecated and |
| 2110 | will mostly likely be removed in Python 3.5. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 2111 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2112 | * The *strict* argument of :class:`~html.parser.HTMLParser` is deprecated. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 2113 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2114 | * The :mod:`plistlib` :func:`~plistlib.readPlist`, |
| 2115 | :func:`~plistlib.writePlist`, :func:`~plistlib.readPlistFromBytes`, and |
| 2116 | :func:`~plistlib.writePlistToBytes` functions are deprecated in favor of the |
| 2117 | corresponding new functions :func:`~plistlib.load`, :func:`~plistlib.dump`, |
| 2118 | :func:`~plistlib.loads`, and :func:`~plistlib.dumps`. :func:`~plistlib.Data` |
| 2119 | is deprecated in favor of just using the :class:`bytes` constructor. |
| 2120 | |
| 2121 | * The :mod:`sysconfig` key ``SO`` is deprecated, it has been replaced by |
| 2122 | ``EXT_SUFFIX``. |
| 2123 | |
| 2124 | * The ``U`` mode accepted by various ``open`` functions is deprecated. |
| 2125 | In Python3 it does not do anything useful, and should be replaced by |
| 2126 | appropriate uses of :class:`io.TextIOWrapper` (if needed) and its *newline* |
| 2127 | argument. |
| 2128 | |
| 2129 | * The *parser* argument of :func:`xml.etree.ElementTree.iterparse` has |
| 2130 | been deprecated, as has the *html* argument of |
| 2131 | :func:`~xml.etree.ElementTree.XMLParser`. To prepare for the removal of the |
| 2132 | latter, all arguments to ``XMLParser`` should be passed by keyword. |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 2133 | |
| 2134 | |
R David Murray | e7cf678 | 2013-12-24 14:51:25 -0500 | [diff] [blame] | 2135 | Deprecated Features |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 2136 | ------------------- |
| 2137 | |
R David Murray | 5ea9524 | 2013-12-24 15:59:57 -0500 | [diff] [blame] | 2138 | * Running :ref:`idle` with the ``-n`` flag (no subprocess) is deprecated. |
| 2139 | However, the feature will not be removed until :issue:`18823` is resolved. |
| 2140 | |
Antoine Pitrou | 3b2f0f0 | 2013-10-25 21:39:26 +0200 | [diff] [blame] | 2141 | * The site module adding a "site-python" directory to sys.path, if it |
| 2142 | exists, is deprecated (:issue:`19375`). |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 2143 | |
| 2144 | |
R David Murray | 5917172 | 2014-01-03 15:52:22 -0500 | [diff] [blame] | 2145 | |
R David Murray | 72420ff | 2013-12-24 10:46:44 -0500 | [diff] [blame] | 2146 | Removed |
| 2147 | ======= |
| 2148 | |
R David Murray | 5917172 | 2014-01-03 15:52:22 -0500 | [diff] [blame] | 2149 | |
| 2150 | Operating Systems No Longer Supported |
| 2151 | ------------------------------------- |
| 2152 | |
| 2153 | Support for the following operating systems has been removed from the source |
| 2154 | and build tools: |
| 2155 | |
| 2156 | * OS/2 (:issue:`16135`). |
| 2157 | * Windows 2000 (changeset e52df05b496a). |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2158 | * Windows systems where ``COMSPEC`` points to ``command.com`` (:issue:`14470`). |
R David Murray | 5917172 | 2014-01-03 15:52:22 -0500 | [diff] [blame] | 2159 | * VMS (:issue:`16136`). |
| 2160 | |
| 2161 | |
| 2162 | API and Feature Removals |
| 2163 | ------------------------ |
| 2164 | |
R David Murray | d265381 | 2013-12-27 14:06:15 -0500 | [diff] [blame] | 2165 | The following obsolete and previously deprecated APIs and features have been |
R David Murray | 5917172 | 2014-01-03 15:52:22 -0500 | [diff] [blame] | 2166 | removed: |
R David Murray | 076dead | 2013-12-24 14:59:50 -0500 | [diff] [blame] | 2167 | |
R David Murray | 72420ff | 2013-12-24 10:46:44 -0500 | [diff] [blame] | 2168 | * The unmaintained ``Misc/TextMate`` and ``Misc/vim`` directories have been |
R David Murray | d91ba20 | 2013-12-24 12:13:44 -0500 | [diff] [blame] | 2169 | removed (see the `devguide <http://docs.python.org/devguide>`_ |
R David Murray | 0056936 | 2014-01-03 13:04:25 -0500 | [diff] [blame] | 2170 | for suggestions on what to use instead). |
R David Murray | 72420ff | 2013-12-24 10:46:44 -0500 | [diff] [blame] | 2171 | |
R David Murray | d17aba7 | 2013-12-24 14:46:23 -0500 | [diff] [blame] | 2172 | * The ``SO`` makefile macro is removed (it was replaced by the |
| 2173 | ``SHLIB_SUFFIX`` and ``EXT_SUFFIX`` macros) (:issue:`16754`). |
| 2174 | |
R David Murray | d74d09a | 2013-12-24 15:33:02 -0500 | [diff] [blame] | 2175 | * The ``PyThreadState.tick_counter`` field has been removed; its value has |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2176 | been meaningless since Python 3.2, when the "new GIL" was introduced |
| 2177 | (:issue:`19199`). |
R David Murray | d74d09a | 2013-12-24 15:33:02 -0500 | [diff] [blame] | 2178 | |
R David Murray | d265381 | 2013-12-27 14:06:15 -0500 | [diff] [blame] | 2179 | * ``PyLoader`` and ``PyPycLoader`` have been removed from :mod:`importlib`. |
| 2180 | (Contributed by Taras Lyapun in :issue:`15641`.) |
| 2181 | |
R David Murray | a2924ca | 2014-01-03 14:06:01 -0500 | [diff] [blame] | 2182 | * The *strict* argument to :class:`~http.client.HTTPConnection` and |
| 2183 | :class:`~http.client.HTTPSConnection` has been removed. HTTP 0.9-style |
| 2184 | "Simple Responses" are no longer supported. |
R David Murray | 0056936 | 2014-01-03 13:04:25 -0500 | [diff] [blame] | 2185 | |
R David Murray | db085f5 | 2014-01-03 15:46:24 -0500 | [diff] [blame] | 2186 | * The deprecated :mod:`urllib.request.Request` getter and setter methods |
| 2187 | ``add_data``, ``has_data``, ``get_data``, ``get_type``, ``get_host``, |
| 2188 | ``get_selector``, ``set_proxy``, ``get_origin_req_host``, and |
| 2189 | ``is_unverifiable`` have been removed (use direct attribute access instead). |
| 2190 | |
R David Murray | 244ad60 | 2014-01-04 21:17:52 -0500 | [diff] [blame] | 2191 | * Support for loading the deprecated ``TYPE_INT64`` has been removed from |
| 2192 | :mod:`marshal`. (Contributed by Dan Riti in :issue:`15480`.) |
| 2193 | |
Yury Selivanov | 2393dca | 2014-01-27 15:07:58 -0500 | [diff] [blame] | 2194 | * :class:`inspect.Signature`: positional-only parameters are now required |
| 2195 | to have a valid name. |
| 2196 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2197 | * :meth:`object.__format__` no longer accepts non-empty format strings, it now |
| 2198 | raises a :exc:`TypeError` instead. Using a non-empty string has been |
| 2199 | deprecated since Python 3.2. This change has been made to prevent a |
| 2200 | situation where previously working (but incorrect) code would start failing |
| 2201 | if an object gained a __format__ method, which means that your code may now |
| 2202 | raise a :exc:`TypeError` if you are using an ``'s'`` format code with objects |
| 2203 | that do not have a __format__ method that handles it. See :issue:`7994` for |
| 2204 | background. |
| 2205 | |
R David Murray | 6dfc632 | 2014-03-13 21:34:54 -0400 | [diff] [blame] | 2206 | * :meth:`difflib.SequenceMatcher.isbjunk` and |
| 2207 | :meth:`difflib.SequenceMatcher.isbpopular` were deprecated in 3.2, and have |
| 2208 | now been removed: use ``x in sm.bjunk`` and |
| 2209 | ``x in sm.bpopular``, where *sm* is a :class:`~difflib.SequenceMatcher` object |
| 2210 | (:issue:`13248`). |
| 2211 | |
R David Murray | 72420ff | 2013-12-24 10:46:44 -0500 | [diff] [blame] | 2212 | |
R David Murray | 9835827 | 2014-01-05 20:52:06 -0500 | [diff] [blame] | 2213 | Code Cleanups |
| 2214 | ------------- |
| 2215 | |
| 2216 | * The unused and undocumented internal ``Scanner`` class has been removed from |
| 2217 | the :mod:`pydoc` module. |
| 2218 | |
R David Murray | bf0ab83 | 2014-02-03 01:14:03 -0500 | [diff] [blame] | 2219 | * The private and effectively unused ``_gestalt`` module has been removed, |
| 2220 | along with the private :mod:`platform` functions ``_mac_ver_lookup``, |
| 2221 | ``_mac_ver_gstalt``, and ``_bcd2str``, which would only have ever been called |
| 2222 | on badly broken OSX systems (see :issue:`18393`). |
| 2223 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2224 | * The hardcoded copies of certain :mod:`stat` constants that were included in |
| 2225 | the :mod:`tarfile` module namespace have been removed. |
| 2226 | |
R David Murray | 9835827 | 2014-01-05 20:52:06 -0500 | [diff] [blame] | 2227 | |
R David Murray | e608255 | 2014-01-03 16:15:45 -0500 | [diff] [blame] | 2228 | |
Benjamin Peterson | 88f3b23 | 2012-10-04 12:45:10 -0400 | [diff] [blame] | 2229 | Porting to Python 3.4 |
Georg Brandl | b80f511 | 2012-09-30 09:11:58 +0200 | [diff] [blame] | 2230 | ===================== |
| 2231 | |
| 2232 | This section lists previously described changes and other bugfixes |
| 2233 | that may require changes to your code. |
| 2234 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2235 | |
| 2236 | Changes in 'python' Command Behavior |
| 2237 | ------------------------------------ |
| 2238 | |
| 2239 | * In a posix shell, setting the :envvar:`PATH` environment variable to |
| 2240 | an empty value is equivalent to not setting it at all. However, setting |
| 2241 | :envvar:`PYTHONPATH` to an empty value was *not* equivalent to not setting it |
| 2242 | at all: setting :envvar:`PYTHONPATH` to an empty value was equivalent to |
| 2243 | setting it to ``.``, which leads to confusion when reasoning by analogy to |
| 2244 | how :envvar:`PATH` works. The behavior now conforms to the posix convention |
| 2245 | for :envvar:`PATH`. |
| 2246 | |
| 2247 | * The [X refs, Y blocks] output of a debug (``--with-pydebug``) build of the |
| 2248 | CPython interpreter is now off by default. It can be re-enabled using the |
| 2249 | ``-X showrefcount`` option. (Contributed by Ezio Melotti in :issue:`17323`.) |
| 2250 | |
| 2251 | * The python command and most stdlib scripts (as well as :mod:`argparse`) now |
| 2252 | output ``--version`` information to ``stdout`` instead of ``stderr`` (for |
| 2253 | issue list see :ref:`other-improvements-3.4` above). |
| 2254 | |
| 2255 | |
R David Murray | d74d09a | 2013-12-24 15:33:02 -0500 | [diff] [blame] | 2256 | Changes in the Python API |
| 2257 | ------------------------- |
| 2258 | |
Brett Cannon | 777622b | 2013-04-09 17:03:10 -0400 | [diff] [blame] | 2259 | * The ABCs defined in :mod:`importlib.abc` now either raise the appropriate |
| 2260 | exception or return a default value instead of raising |
| 2261 | :exc:`NotImplementedError` blindly. This will only affect code calling |
| 2262 | :func:`super` and falling through all the way to the ABCs. For compatibility, |
| 2263 | catch both :exc:`NotImplementedError` or the appropriate exception as needed. |
Brett Cannon | 4c14b5d | 2013-05-04 13:56:58 -0400 | [diff] [blame] | 2264 | |
| 2265 | * The module type now initializes the :attr:`__package__` and :attr:`__loader__` |
| 2266 | attributes to ``None`` by default. To determine if these attributes were set |
| 2267 | in a backwards-compatible fashion, use e.g. |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2268 | ``getattr(module, '__loader__', None) is not None``. (:issue:`17115`.) |
Brett Cannon | 3dc48d6 | 2013-05-28 18:35:54 -0400 | [diff] [blame] | 2269 | |
| 2270 | * :meth:`importlib.util.module_for_loader` now sets ``__loader__`` and |
| 2271 | ``__package__`` unconditionally to properly support reloading. If this is not |
| 2272 | desired then you will need to set these attributes manually. You can use |
Brett Cannon | 028d512 | 2013-05-31 18:02:11 -0400 | [diff] [blame] | 2273 | :func:`importlib.util.module_to_load` for module management. |
Brett Cannon | 3e0651b | 2013-05-31 23:18:39 -0400 | [diff] [blame] | 2274 | |
| 2275 | * Import now resets relevant attributes (e.g. ``__name__``, ``__loader__``, |
| 2276 | ``__package__``, ``__file__``, ``__cached__``) unconditionally when reloading. |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2277 | Note that this restores a pre-3.3 behavior in that it means a module is |
| 2278 | re-found when re-loaded (:issue:`19413`). |
Brett Cannon | 3e0651b | 2013-05-31 23:18:39 -0400 | [diff] [blame] | 2279 | |
Brett Cannon | 1448ecf | 2013-10-04 11:38:59 -0400 | [diff] [blame] | 2280 | * Frozen packages no longer set ``__path__`` to a list containing the package |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2281 | name, they now set it to an empty list. The previous behavior could cause |
| 2282 | the import system to do the wrong thing on submodule imports if there was |
| 2283 | also a directory with the same name as the frozen package. The correct way |
Larry Hastings | 0548f5c | 2014-03-15 22:29:19 -0700 | [diff] [blame] | 2284 | to determine if a module is a package or not is to use ``hasattr(module, |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2285 | '__path__')`` (:issue:`18065`). |
| 2286 | |
| 2287 | * Frozen modules no longer define a ``__file__`` attribute. It's semantically |
| 2288 | incorrect for frozen modules to set the attribute as they are not loaded from |
| 2289 | any explicit location. If you must know that a module comes from frozen code |
| 2290 | then you can see if the module's ``__spec__.location`` is set to ``'frozen'``, |
| 2291 | check if the loader is a subclass of |
| 2292 | :class:`importlib.machinery.FrozenImporter`, |
| 2293 | or if Python 2 compatibility is necessary you can use :func:`imp.is_frozen`. |
Brett Cannon | 8f5ac51 | 2013-06-12 23:29:18 -0400 | [diff] [blame] | 2294 | |
Brett Cannon | 33915eb | 2013-06-14 18:33:00 -0400 | [diff] [blame] | 2295 | * :func:`py_compile.compile` now raises :exc:`FileExistsError` if the file path |
| 2296 | it would write to is a symlink or a non-regular file. This is to act as a |
| 2297 | warning that import will overwrite those files with a regular file regardless |
| 2298 | of what type of file path they were originally. |
Brett Cannon | f4375ef | 2013-06-16 18:05:54 -0400 | [diff] [blame] | 2299 | |
| 2300 | * :meth:`importlib.abc.SourceLoader.get_source` no longer raises |
| 2301 | :exc:`ImportError` when the source code being loaded triggers a |
| 2302 | :exc:`SyntaxError` or :exc:`UnicodeDecodeError`. As :exc:`ImportError` is |
| 2303 | meant to be raised only when source code cannot be found but it should, it was |
| 2304 | felt to be over-reaching/overloading of that meaning when the source code is |
| 2305 | found but improperly structured. If you were catching ImportError before and |
| 2306 | wish to continue to ignore syntax or decoding issues, catch all three |
Victor Stinner | 84e33c8 | 2013-06-21 00:31:55 +0200 | [diff] [blame] | 2307 | exceptions now. |
Nick Coghlan | 24c05bc | 2013-07-15 21:13:08 +1000 | [diff] [blame] | 2308 | |
| 2309 | * :func:`functools.update_wrapper` and :func:`functools.wraps` now correctly |
R David Murray | bf0ab83 | 2014-02-03 01:14:03 -0500 | [diff] [blame] | 2310 | set the ``__wrapped__`` attribute to the function being wrapped, even if |
Nick Coghlan | 367df12 | 2013-10-27 01:57:34 +1000 | [diff] [blame] | 2311 | that function also had its ``__wrapped__`` attribute set. This means |
| 2312 | ``__wrapped__`` attributes now correctly link a stack of decorated |
| 2313 | functions rather than every ``__wrapped__`` attribute in the chain |
| 2314 | referring to the innermost function. Introspection libraries that |
| 2315 | assumed the previous behaviour was intentional can use |
| 2316 | :func:`inspect.unwrap` to access the first function in the chain that has |
| 2317 | no ``__wrapped__`` attribute. |
Victor Stinner | 2fe9bac | 2013-10-10 16:18:20 +0200 | [diff] [blame] | 2318 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2319 | * :func:`inspect.getfullargspec` has been reimplemented on top of |
| 2320 | :func:`inspect.signature` and hence handles a much wider variety of callable |
| 2321 | objects than it did in the past. It is expected that additional builtin and |
| 2322 | extension module callables will gain signature metadata over the course of |
| 2323 | the Python 3.4 series. Code that assumes that |
| 2324 | :func:`inspect.getfullargspec` will fail on non-Python callables may need |
| 2325 | to be adjusted accordingly. |
| 2326 | |
Georg Brandl | 0f5bff2 | 2013-10-19 17:46:38 +0200 | [diff] [blame] | 2327 | * :class:`importlib.machinery.PathFinder` now passes on the current working |
Brett Cannon | 27e27f7 | 2013-10-18 11:39:04 -0400 | [diff] [blame] | 2328 | directory to objects in :data:`sys.path_hooks` for the empty string. This |
| 2329 | results in :data:`sys.path_importer_cache` never containing ``''``, thus |
| 2330 | iterating through :data:`sys.path_importer_cache` based on :data:`sys.path` |
| 2331 | will not find all keys. A module's ``__file__`` when imported in the current |
| 2332 | working directory will also now have an absolute path, including when using |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2333 | ``-m`` with the interpreter (except for ``__main__.__file__`` when a script |
| 2334 | has been executed directly using a relative path) (Contributed by Brett |
| 2335 | Cannon in :issue:`18416`). is specified on the command-line) |
| 2336 | (:issue:`18416`). |
Victor Stinner | 2748bc7 | 2013-12-13 10:57:04 +0100 | [diff] [blame] | 2337 | |
R David Murray | a2924ca | 2014-01-03 14:06:01 -0500 | [diff] [blame] | 2338 | * The removal of the *strict* argument to :class:`~http.client.HTTPConnection` |
| 2339 | and :class:`~http.client.HTTPSConnection` changes the meaning of the |
| 2340 | remaining arguments if you are specifying them positionally rather than by |
| 2341 | keyword. If you've been paying attention to deprecation warnings your code |
| 2342 | should already be specifying any additional arguments via keywords. |
| 2343 | |
R David Murray | 4908f4a | 2014-01-04 18:07:20 -0500 | [diff] [blame] | 2344 | * Strings between ``from __future__ import ...`` statements now *always* raise |
| 2345 | a :exc:`SyntaxError`. Previously if there was no leading docstring, an |
| 2346 | interstitial string would sometimes be ignored. This brings CPython into |
| 2347 | compliance with the language spec; Jython and PyPy already were. |
| 2348 | (:issue:`17434`). |
| 2349 | |
R David Murray | a101bdb | 2014-01-06 16:32:05 -0500 | [diff] [blame] | 2350 | * :meth:`ssl.SSLSocket.getpeercert` and :meth:`ssl.SSLSocket.do_handshake` |
| 2351 | now raise an :exc:`OSError` with ``ENOTCONN`` when the ``SSLSocket`` is not |
| 2352 | connected, instead of the previous behavior of raising an |
| 2353 | :exc:`AttributError`. In addition, :meth:`~ssl.SSLSocket.getpeercert` |
| 2354 | will raise a :exc:`ValueError` if the handshake has not yet been done. |
| 2355 | |
R David Murray | 0ae7ae1 | 2014-01-08 18:16:02 -0500 | [diff] [blame] | 2356 | * :func:`base64.b32decode` now raises a :exc:`binascii.Error` when the |
| 2357 | input string contains non-b32-alphabet characters, instead of a |
| 2358 | :exc:`TypeError`. This particular :exc:`TypeError` was missed when the other |
| 2359 | :exc:`TypeError`\ s were converted. (Contributed by Serhiy Storchaka in |
| 2360 | :issue:`18011`.) Note: this change was also inadvertently applied in Python |
| 2361 | 3.3.3. |
| 2362 | |
Brett Cannon | c089f70 | 2014-01-17 11:03:19 -0500 | [diff] [blame] | 2363 | * The :attr:`~cgi.FieldStorage.file` attribute is now automatically closed when |
| 2364 | the creating :class:`cgi.FieldStorage` instance is garbage collected. If you |
| 2365 | were pulling the file object out separately from the :class:`cgi.FieldStorage` |
| 2366 | instance and not keeping the instance alive, then you should either store the |
| 2367 | entire :class:`cgi.FieldStorage` instance or read the contents of the file |
| 2368 | before the :class:`cgi.FieldStorage` instance is garbage collected. |
| 2369 | |
R David Murray | 45e732d | 2014-02-03 01:33:39 -0500 | [diff] [blame] | 2370 | * Calling ``read`` or ``write`` on a closed SSL socket now raises an |
| 2371 | informative :exc:`ValueError` rather than the previous more mysterious |
| 2372 | :exc:`AttributeError` (:issue:`9177`). |
| 2373 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2374 | * :meth:`slice.indices` no longer produces an :exc:`OverflowError` for huge |
| 2375 | values. As a consequence of this fix, :meth:`slice.indices` now raises a |
| 2376 | :exc:`ValueError` if given a negative length; previously it returned nonsense |
| 2377 | values (:issue:`14794`). |
| 2378 | |
| 2379 | * The :class:`complex` constructor, unlike the :mod:`cmath` functions, was |
| 2380 | incorrectly accepting :class:`float` values if an object's ``__complex__`` |
| 2381 | special method returned one. This now raises a :exc:`TypeError`. |
| 2382 | (:issue:`16290`.) |
| 2383 | |
| 2384 | * The :class:`int` constructor in 3.2 and 3.3 erroneously accepts :class:`float` |
| 2385 | values for the *base* parameter. It is unlikely anyone was doing this, but |
| 2386 | if so, it will now raise a :exc:`TypeError` (:issue:`16772`). |
| 2387 | |
| 2388 | * Defaults for keyword-only arguments are now evaluated *after* defaults for |
| 2389 | regular keyword arguments, instead of before. Hopefully no one wrote any |
| 2390 | code that depends on the previous buggy behavior (:issue:`16967`). |
| 2391 | |
| 2392 | * Stale thread states are now cleared after :func:`~os.fork`. This may cause |
| 2393 | some system resources to be released that previously were incorrectly kept |
| 2394 | perpetually alive (for example, database connections kept in thread-local |
| 2395 | storage). (:issue:`17094`.) |
| 2396 | |
| 2397 | * Parameter names in ``__annotations__`` dicts are now mangled properly, |
Yury Selivanov | 026019f | 2014-02-18 12:49:41 -0500 | [diff] [blame] | 2398 | similarly to ``__kwdefaults__``. (Contributed by Yury Selivanov in |
| 2399 | :issue:`20625`). |
| 2400 | |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2401 | * :attr:`hashlib.hash.name` now always returns the identifier in lower case. |
| 2402 | Previously some builtin hashes had uppercase names, but now that it is a |
| 2403 | formal public interface the naming has been made consistent (:issue:`18532`). |
| 2404 | |
| 2405 | * Because :mod:`unittest.TestSuite` now drops references to tests after they |
| 2406 | are run, test harnesses that re-use a :class:`~unittest.TestSuite` to re-run |
| 2407 | a set of tests may fail. Test suites should not be re-used in this fashion |
| 2408 | since it means state is retained between test runs, breaking the test |
| 2409 | isolation that :mod:`unittest` is designed to provide. However, if the lack |
| 2410 | of isolation is considered acceptable, the old behavior can be restored by |
| 2411 | creating a :mod:`~unittest.TestSuite` subclass that defines a |
| 2412 | ``_removeTestAtIndex`` method that does nothing (see |
| 2413 | :meth:`.TestSuite.__iter__`) (:issue:`11798`). |
| 2414 | |
| 2415 | * :mod:`unittest` now uses :mod:`argparse` for command line parsing. There are |
| 2416 | certain invalid command forms that used to work that are no longer allowed; |
| 2417 | in theory this should not cause backward compatibility issues since the |
| 2418 | disallowed command forms didn't make any sense and are unlikely to be in use. |
| 2419 | |
| 2420 | * The :func:`re.split`, :func:`re.findall`, and :func:`re.sub` functions, and |
| 2421 | the :meth:`~re.match.group` and :meth:`~re.match.groups` methods of |
| 2422 | ``match`` objects now always return a *bytes* object when the string |
| 2423 | to be matched is a :term:`bytes-like object`. Previously the return type |
| 2424 | matched the input type, so if your code was depending on the return value |
| 2425 | being, say, a ``bytearray``, you will need to change your code. |
| 2426 | |
| 2427 | * :mod:`audioop` functions now raise an error immediately if passed string |
| 2428 | input, instead of failing randomly later on (:issue:`16685`). |
| 2429 | |
| 2430 | * The new *convert_charrefs* argument to :class:`~html.parser.HTMLParser` |
| 2431 | currently defaults to ``False`` for backward compatibility, but will |
| 2432 | eventually be changed to default to ``True``. It is recommended that you add |
| 2433 | this keyword, with the appropriate value, to any |
| 2434 | :class:`~html.parser.HTMLParser` calls in your code (:issue:`13633`). |
| 2435 | |
| 2436 | * Since the *digestmod* argument to the :func:`hmac.new` function will in the |
| 2437 | future have no default, all calls to :func:`hmac.new` should be changed to |
| 2438 | explicitly specify a *digestmod* (:issue:`17276`). |
| 2439 | |
| 2440 | * Calling :func:`sysconfig.get_config_var` with the ``SO`` key, or looking |
| 2441 | ``SO`` up in the results of a call to :func:`sysconfig.get_config_vars` |
| 2442 | is deprecated. This key should be replaced by ``EXT_SUFFIX`` or |
| 2443 | ``SHLIB_SUFFIX``, depending on the context (:issue:`19555`). |
| 2444 | |
| 2445 | * Any calls to ``open`` functions that specify ``U`` should be modified. |
| 2446 | ``U`` is ineffective in Python3 and will eventually raise an error if used. |
| 2447 | Depending on the function, the equivalent of its old Python2 behavior can be |
| 2448 | achieved using either a *newline* argument, or if necessary by wrapping the |
| 2449 | stream in :mod:`~io.TextIOWrapper` to use its *newline* argument |
| 2450 | (:issue:`15204`). |
| 2451 | |
| 2452 | * If you use :ref:`pyvenv <scripts-pyvenv>` in a script and desire that pip |
| 2453 | *not* be installed, you must add ``--without-pip`` to your command |
| 2454 | invocation. |
| 2455 | |
| 2456 | * The default behavior of :func:`json.dump` and :func:`json.dumps` when |
| 2457 | an indent is specified has changed: it no longer produces trailing |
| 2458 | spaces after the item separating commas at the ends of lines. This |
| 2459 | will matter only if you have tests that are doing white-space-sensitive |
| 2460 | comparisons of such output (:issue:`16333`). |
| 2461 | |
| 2462 | * :mod:`doctest` now looks for doctests in extension module ``__doc__`` |
| 2463 | strings, so if your doctest test discovery includes extension modules that |
| 2464 | have things that look like doctests in them you may see test failures you've |
| 2465 | never seen before when running your tests (:issue:`3158`). |
| 2466 | |
| 2467 | * The :mod:`collections.abc` module has been slightly refactored as |
| 2468 | part of the Python startup improvements. As a consequence of this, it is no |
| 2469 | longer the case that importing :mod:`collections` automatically imports |
| 2470 | :mod:`collections.abc`. If your program depended on the (undocumented) |
| 2471 | implicit import, you will need to add an explicit ``import collections.abc`` |
| 2472 | (:issue:`20784`). |
| 2473 | |
R David Murray | d265381 | 2013-12-27 14:06:15 -0500 | [diff] [blame] | 2474 | |
Victor Stinner | 774b2e0 | 2013-12-13 14:33:01 +0100 | [diff] [blame] | 2475 | Changes in the C API |
| 2476 | -------------------- |
| 2477 | |
Larry Hastings | ad88d7a | 2014-02-10 04:26:10 -0800 | [diff] [blame] | 2478 | * :c:func:`PyEval_EvalFrameEx`, :c:func:`PyObject_Repr`, and |
Nick Coghlan | c0bc0b4 | 2014-02-09 12:00:01 +1000 | [diff] [blame] | 2479 | :c:func:`PyObject_Str`, along with some other internal C APIs, now include |
| 2480 | a debugging assertion that ensures they are not used in situations where |
| 2481 | they may silently discard a currently active exception. In cases where |
Nick Coghlan | 3d7b364 | 2014-02-09 10:57:34 +1000 | [diff] [blame] | 2482 | discarding the active exception is expected and desired (for example, |
Nick Coghlan | c0bc0b4 | 2014-02-09 12:00:01 +1000 | [diff] [blame] | 2483 | because it has already been saved locally with :c:func:`PyErr_Fetch` or |
| 2484 | is being deliberately replaced with a different exception), an explicit |
| 2485 | :c:func:`PyErr_Clear` call will be needed to avoid triggering the |
Nick Coghlan | 72318b9 | 2014-02-09 12:05:13 +1000 | [diff] [blame] | 2486 | assertion when invoking these operations (directly or indirectly) and |
| 2487 | running against a version of Python that is compiled with assertions |
| 2488 | enabled. |
Nick Coghlan | 3d7b364 | 2014-02-09 10:57:34 +1000 | [diff] [blame] | 2489 | |
Victor Stinner | 774b2e0 | 2013-12-13 14:33:01 +0100 | [diff] [blame] | 2490 | * :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg** |
| 2491 | argument is not set. Previously only ``NULL`` was returned with no exception |
| 2492 | set. |
| 2493 | |
| 2494 | * The result of the :c:data:`PyOS_ReadlineFunctionPointer` callback must |
| 2495 | now be a string allocated by :c:func:`PyMem_RawMalloc` or |
| 2496 | :c:func:`PyMem_RawRealloc`, or *NULL* if an error occurred, instead of a |
Larry Hastings | 3732ed2 | 2014-03-15 21:13:56 -0700 | [diff] [blame] | 2497 | string allocated by :c:func:`PyMem_Malloc` or :c:func:`PyMem_Realloc` |
| 2498 | (:issue:`16742`) |
Victor Stinner | 774b2e0 | 2013-12-13 14:33:01 +0100 | [diff] [blame] | 2499 | |
| 2500 | * :c:func:`PyThread_set_key_value` now always set the value. In Python |
Victor Stinner | 2748bc7 | 2013-12-13 10:57:04 +0100 | [diff] [blame] | 2501 | 3.3, the function did nothing if the key already exists (if the current |
| 2502 | value is a non-NULL pointer). |
| 2503 | |
Victor Stinner | 774b2e0 | 2013-12-13 14:33:01 +0100 | [diff] [blame] | 2504 | * The ``f_tstate`` (thread state) field of the :c:type:`PyFrameObject` |
| 2505 | structure has been removed to fix a bug: see :issue:`14432` for the |
| 2506 | rationale. |