Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 1 | **************************** |
| 2 | What's New In Python 3.3 |
| 3 | **************************** |
| 4 | |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 5 | :Release: |release| |
| 6 | :Date: |today| |
| 7 | |
Éric Araujo | b07b97f | 2011-10-05 01:03:34 +0200 | [diff] [blame] | 8 | .. Rules for maintenance: |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 9 | |
| 10 | * Anyone can add text to this document. Do not spend very much time |
| 11 | on the wording of your changes, because your text will probably |
| 12 | get rewritten to some degree. |
| 13 | |
| 14 | * The maintainer will go through Misc/NEWS periodically and add |
| 15 | changes; it's therefore more important to add your changes to |
| 16 | Misc/NEWS than to this file. |
| 17 | |
| 18 | * This is not a complete list of every single change; completeness |
| 19 | is the purpose of Misc/NEWS. Some changes I consider too small |
| 20 | or esoteric to include. If such a change is added to the text, |
| 21 | I'll just remove it. (This is another reason you shouldn't spend |
| 22 | too much time on writing your addition.) |
| 23 | |
| 24 | * If you want to draw your new text to the attention of the |
| 25 | maintainer, add 'XXX' to the beginning of the paragraph or |
| 26 | section. |
| 27 | |
| 28 | * It's OK to just add a fragmentary note about a change. For |
| 29 | example: "XXX Describe the transmogrify() function added to the |
| 30 | socket module." The maintainer will research the change and |
| 31 | write the necessary text. |
| 32 | |
| 33 | * You can comment out your additions if you like, but it's not |
| 34 | necessary (especially when a final release is some months away). |
| 35 | |
| 36 | * Credit the author of a patch or bugfix. Just the name is |
| 37 | sufficient; the e-mail address isn't necessary. |
| 38 | |
| 39 | * It's helpful to add the bug/patch number as a comment: |
| 40 | |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 41 | XXX Describe the transmogrify() function added to the socket |
| 42 | module. |
Éric Araujo | b07b97f | 2011-10-05 01:03:34 +0200 | [diff] [blame] | 43 | (Contributed by P.Y. Developer in :issue:`12345`.) |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 44 | |
Éric Araujo | b07b97f | 2011-10-05 01:03:34 +0200 | [diff] [blame] | 45 | This saves the maintainer the effort of going through the Mercurial log |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 46 | when researching a change. |
| 47 | |
| 48 | This article explains the new features in Python 3.3, compared to 3.2. |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 49 | Python 3.3 was released on September 29, 2012. For full details, |
| 50 | see the :source:`Misc/NEWS` file. |
| 51 | |
| 52 | .. seealso:: |
| 53 | |
Nick Coghlan | cfb1818 | 2012-09-30 12:08:13 +0530 | [diff] [blame] | 54 | :pep:`398` - Python 3.3 Release Schedule |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 55 | |
Nick Coghlan | b47b539 | 2012-05-26 01:31:25 +1000 | [diff] [blame] | 56 | |
Antoine Pitrou | c907de9 | 2012-08-21 00:53:06 +0200 | [diff] [blame] | 57 | Summary -- Release highlights |
| 58 | ============================= |
Victor Stinner | 636130e | 2012-08-05 16:37:12 +0200 | [diff] [blame] | 59 | |
Antoine Pitrou | c907de9 | 2012-08-21 00:53:06 +0200 | [diff] [blame] | 60 | .. This section singles out the most important changes in Python 3.3. |
| 61 | Brevity is key. |
Victor Stinner | 636130e | 2012-08-05 16:37:12 +0200 | [diff] [blame] | 62 | |
Antoine Pitrou | c907de9 | 2012-08-21 00:53:06 +0200 | [diff] [blame] | 63 | New syntax features: |
Victor Stinner | 636130e | 2012-08-05 16:37:12 +0200 | [diff] [blame] | 64 | |
Antoine Pitrou | c907de9 | 2012-08-21 00:53:06 +0200 | [diff] [blame] | 65 | * New ``yield from`` expression for :ref:`generator delegation <pep-380>`. |
| 66 | * The ``u'unicode'`` syntax is accepted again for :class:`str` objects. |
Victor Stinner | 636130e | 2012-08-05 16:37:12 +0200 | [diff] [blame] | 67 | |
Antoine Pitrou | c907de9 | 2012-08-21 00:53:06 +0200 | [diff] [blame] | 68 | New library modules: |
| 69 | |
| 70 | * :mod:`faulthandler` (helps debugging low-level crashes) |
| 71 | * :mod:`ipaddress` (high-level objects representing IP addresses and masks) |
| 72 | * :mod:`lzma` (compress data using the XZ / LZMA algorithm) |
Victor Stinner | 1da769a | 2012-09-18 22:40:03 +0200 | [diff] [blame] | 73 | * :mod:`unittest.mock` (replace parts of your system under test with mock objects) |
Antoine Pitrou | c907de9 | 2012-08-21 00:53:06 +0200 | [diff] [blame] | 74 | * :mod:`venv` (Python :ref:`virtual environments <pep-405>`, as in the |
| 75 | popular ``virtualenv`` package) |
| 76 | |
| 77 | New built-in features: |
| 78 | |
| 79 | * Reworked :ref:`I/O exception hierarchy <pep-3151>`. |
| 80 | |
| 81 | Implementation improvements: |
| 82 | |
| 83 | * Rewritten :ref:`import machinery <importlib>` based on :mod:`importlib`. |
| 84 | * More compact :ref:`unicode strings <pep-393>`. |
| 85 | * More compact :ref:`attribute dictionaries <pep-412>`. |
| 86 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 87 | Significantly Improved Library Modules: |
| 88 | |
| 89 | * C Accelerator for the :ref:`decimal <new-decimal>` module. |
| 90 | * Better unicode handling in the :ref:`email <new-email>` module |
| 91 | (:term:`provisional <provisional package>`). |
| 92 | |
Antoine Pitrou | c907de9 | 2012-08-21 00:53:06 +0200 | [diff] [blame] | 93 | Security improvements: |
| 94 | |
| 95 | * Hash randomization is switched on by default. |
| 96 | |
| 97 | Please read on for a comprehensive list of user-facing changes. |
| 98 | |
| 99 | |
| 100 | .. _pep-405: |
Victor Stinner | 636130e | 2012-08-05 16:37:12 +0200 | [diff] [blame] | 101 | |
Éric Araujo | 859aad6 | 2012-06-24 00:07:41 -0400 | [diff] [blame] | 102 | PEP 405: Virtual Environments |
| 103 | ============================= |
Nick Coghlan | b47b539 | 2012-05-26 01:31:25 +1000 | [diff] [blame] | 104 | |
Antoine Pitrou | a5e5797 | 2012-08-21 01:08:17 +0200 | [diff] [blame] | 105 | Virtual environments help create separate Python setups while sharing a |
| 106 | system-wide base install, for ease of maintenance. Virtual environments |
| 107 | have their own set of private site packages (i.e. locally-installed |
| 108 | libraries), and are optionally segregated from the system-wide site |
| 109 | packages. Their concept and implementation are inspired by the popular |
| 110 | ``virtualenv`` third-party package, but benefit from tighter integration |
| 111 | with the interpreter core. |
Éric Araujo | 859aad6 | 2012-06-24 00:07:41 -0400 | [diff] [blame] | 112 | |
Antoine Pitrou | a5e5797 | 2012-08-21 01:08:17 +0200 | [diff] [blame] | 113 | This PEP adds the :mod:`venv` module for programmatic access, and the |
| 114 | :ref:`pyvenv <scripts-pyvenv>` script for command-line access and |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 115 | administration. The Python interpreter checks for a ``pvenv.cfg``, |
Antoine Pitrou | a5e5797 | 2012-08-21 01:08:17 +0200 | [diff] [blame] | 116 | file whose existence signals the base of a virtual environment's directory |
| 117 | tree. |
Nick Coghlan | b47b539 | 2012-05-26 01:31:25 +1000 | [diff] [blame] | 118 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 119 | (Implemented by Carl Meyer and Vinay Sajip.) |
| 120 | |
| 121 | .. seealso:: |
| 122 | |
| 123 | :pep:`405` - Python Virtual Environments |
| 124 | PEP written by Carl Meyer |
| 125 | |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 126 | |
Éric Araujo | 859aad6 | 2012-06-24 00:07:41 -0400 | [diff] [blame] | 127 | PEP 420: Namespace Packages |
| 128 | =========================== |
| 129 | |
| 130 | Native support for package directories that don't require ``__init__.py`` |
| 131 | marker files and can automatically span multiple path segments (inspired by |
| 132 | various third party approaches to namespace packages, as described in |
| 133 | :pep:`420`) |
| 134 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 135 | .. seealso:: |
| 136 | |
| 137 | :pep:`420` - Namespace packages |
| 138 | PEP written by Eric V. Smith; implementation by Eric V. Smith |
| 139 | and Barry Warsaw |
| 140 | |
Éric Araujo | 859aad6 | 2012-06-24 00:07:41 -0400 | [diff] [blame] | 141 | |
| 142 | .. _pep-3118-update: |
Nick Coghlan | 98e2070 | 2012-03-06 21:50:13 +1000 | [diff] [blame] | 143 | |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 144 | PEP 3118: New memoryview implementation and buffer protocol documentation |
| 145 | ========================================================================= |
| 146 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 147 | The implementation of :pep:`3118` has been significantly improved. |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 148 | |
| 149 | The new memoryview implementation comprehensively fixes all ownership and |
| 150 | lifetime issues of dynamically allocated fields in the Py_buffer struct |
| 151 | that led to multiple crash reports. Additionally, several functions that |
| 152 | crashed or returned incorrect results for non-contiguous or multi-dimensional |
| 153 | input have been fixed. |
| 154 | |
| 155 | The memoryview object now has a PEP-3118 compliant getbufferproc() |
| 156 | that checks the consumer's request type. Many new features have been |
| 157 | added, most of them work in full generality for non-contiguous arrays |
| 158 | and arrays with suboffsets. |
| 159 | |
| 160 | The documentation has been updated, clearly spelling out responsibilities |
| 161 | for both exporters and consumers. Buffer request flags are grouped into |
| 162 | basic and compound flags. The memory layout of non-contiguous and |
| 163 | multi-dimensional NumPy-style arrays is explained. |
| 164 | |
| 165 | Features |
| 166 | -------- |
| 167 | |
| 168 | * All native single character format specifiers in struct module syntax |
| 169 | (optionally prefixed with '@') are now supported. |
| 170 | |
| 171 | * With some restrictions, the cast() method allows changing of format and |
| 172 | shape of C-contiguous arrays. |
| 173 | |
| 174 | * Multi-dimensional list representations are supported for any array type. |
| 175 | |
| 176 | * Multi-dimensional comparisons are supported for any array type. |
| 177 | |
Stefan Krah | 9e31d36 | 2012-09-08 15:35:01 +0200 | [diff] [blame] | 178 | * One-dimensional memoryviews of hashable (read-only) types with formats B, |
| 179 | b or c are now hashable. (Contributed by Antoine Pitrou in :issue:`13411`) |
Nick Coghlan | 98e2070 | 2012-03-06 21:50:13 +1000 | [diff] [blame] | 180 | |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 181 | * Arbitrary slicing of any 1-D arrays type is supported. For example, it |
| 182 | is now possible to reverse a memoryview in O(1) by using a negative step. |
| 183 | |
| 184 | API changes |
| 185 | ----------- |
| 186 | |
| 187 | * The maximum number of dimensions is officially limited to 64. |
| 188 | |
| 189 | * The representation of empty shape, strides and suboffsets is now |
| 190 | an empty tuple instead of None. |
| 191 | |
| 192 | * Accessing a memoryview element with format 'B' (unsigned bytes) |
| 193 | now returns an integer (in accordance with the struct module syntax). |
| 194 | For returning a bytes object the view must be cast to 'c' first. |
| 195 | |
Nick Coghlan | 06e1ab0 | 2012-08-25 17:59:50 +1000 | [diff] [blame] | 196 | * memoryview comparisons now use the logical structure of the operands |
| 197 | and compare all array elements by value. All format strings in struct |
| 198 | module syntax are supported. Views with unrecognised format strings |
| 199 | are still permitted, but will always compare as unequal, regardless |
| 200 | of view contents. |
| 201 | |
Stefan Krah | 54c3203 | 2012-02-29 17:47:21 +0100 | [diff] [blame] | 202 | * For further changes see `Build and C API Changes`_ and `Porting C code`_ . |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 203 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 204 | (Contributed by Stefan Krah in :issue:`10181`) |
| 205 | |
| 206 | .. seealso:: |
| 207 | |
| 208 | :pep:`3118` - Revising the Buffer Protocol |
| 209 | |
| 210 | |
Antoine Pitrou | 037ffbf | 2011-10-24 00:25:41 +0200 | [diff] [blame] | 211 | .. _pep-393: |
| 212 | |
Ezio Melotti | 48a2f8f | 2011-09-29 00:18:19 +0300 | [diff] [blame] | 213 | PEP 393: Flexible String Representation |
| 214 | ======================================= |
| 215 | |
Antoine Pitrou | fd9b416 | 2011-10-24 00:14:43 +0200 | [diff] [blame] | 216 | The Unicode string type is changed to support multiple internal |
| 217 | representations, depending on the character with the largest Unicode ordinal |
| 218 | (1, 2, or 4 bytes) in the represented string. This allows a space-efficient |
| 219 | representation in common cases, but gives access to full UCS-4 on all |
| 220 | systems. For compatibility with existing APIs, several representations may |
| 221 | exist in parallel; over time, this compatibility should be phased out. |
Ezio Melotti | 397546a | 2011-09-29 08:34:36 +0300 | [diff] [blame] | 222 | |
Antoine Pitrou | fd9b416 | 2011-10-24 00:14:43 +0200 | [diff] [blame] | 223 | On the Python side, there should be no downside to this change. |
Ezio Melotti | 397546a | 2011-09-29 08:34:36 +0300 | [diff] [blame] | 224 | |
Antoine Pitrou | fd9b416 | 2011-10-24 00:14:43 +0200 | [diff] [blame] | 225 | On the C API side, PEP 393 is fully backward compatible. The legacy API |
| 226 | should remain available at least five years. Applications using the legacy |
| 227 | API will not fully benefit of the memory reduction, or - worse - may use |
| 228 | a bit more memory, because Python may have to maintain two versions of each |
| 229 | string (in the legacy format and in the new efficient storage). |
| 230 | |
Antoine Pitrou | 0599b5b | 2011-11-29 22:45:07 +0100 | [diff] [blame] | 231 | Functionality |
| 232 | ------------- |
| 233 | |
Antoine Pitrou | fd9b416 | 2011-10-24 00:14:43 +0200 | [diff] [blame] | 234 | Changes introduced by :pep:`393` are the following: |
Ezio Melotti | 48a2f8f | 2011-09-29 00:18:19 +0300 | [diff] [blame] | 235 | |
Ezio Melotti | 397546a | 2011-09-29 08:34:36 +0300 | [diff] [blame] | 236 | * Python now always supports the full range of Unicode codepoints, including |
| 237 | non-BMP ones (i.e. from ``U+0000`` to ``U+10FFFF``). The distinction between |
| 238 | narrow and wide builds no longer exists and Python now behaves like a wide |
Antoine Pitrou | fd9b416 | 2011-10-24 00:14:43 +0200 | [diff] [blame] | 239 | build, even under Windows. |
Ezio Melotti | 397546a | 2011-09-29 08:34:36 +0300 | [diff] [blame] | 240 | |
Antoine Pitrou | fd9b416 | 2011-10-24 00:14:43 +0200 | [diff] [blame] | 241 | * With the death of narrow builds, the problems specific to narrow builds have |
| 242 | also been fixed, for example: |
Ezio Melotti | 397546a | 2011-09-29 08:34:36 +0300 | [diff] [blame] | 243 | |
| 244 | * :func:`len` now always returns 1 for non-BMP characters, |
| 245 | so ``len('\U0010FFFF') == 1``; |
| 246 | |
| 247 | * surrogate pairs are not recombined in string literals, |
| 248 | so ``'\uDBFF\uDFFF' != '\U0010FFFF'``; |
| 249 | |
Antoine Pitrou | fd9b416 | 2011-10-24 00:14:43 +0200 | [diff] [blame] | 250 | * indexing or slicing non-BMP characters returns the expected value, |
Ezio Melotti | 397546a | 2011-09-29 08:34:36 +0300 | [diff] [blame] | 251 | so ``'\U0010FFFF'[0]`` now returns ``'\U0010FFFF'`` and not ``'\uDBFF'``; |
| 252 | |
Antoine Pitrou | d136aec | 2011-11-17 01:48:06 +0100 | [diff] [blame] | 253 | * all other functions in the standard library now correctly handle |
Antoine Pitrou | fd9b416 | 2011-10-24 00:14:43 +0200 | [diff] [blame] | 254 | non-BMP codepoints. |
Ezio Melotti | 397546a | 2011-09-29 08:34:36 +0300 | [diff] [blame] | 255 | |
Ezio Melotti | 48a2f8f | 2011-09-29 00:18:19 +0300 | [diff] [blame] | 256 | * The value of :data:`sys.maxunicode` is now always ``1114111`` (``0x10FFFF`` |
| 257 | in hexadecimal). The :c:func:`PyUnicode_GetMax` function still returns |
| 258 | either ``0xFFFF`` or ``0x10FFFF`` for backward compatibility, and it should |
| 259 | not be used with the new Unicode API (see :issue:`13054`). |
| 260 | |
Ezio Melotti | 397546a | 2011-09-29 08:34:36 +0300 | [diff] [blame] | 261 | * The :file:`./configure` flag ``--with-wide-unicode`` has been removed. |
Victor Stinner | 7d637ab | 2011-09-29 02:56:16 +0200 | [diff] [blame] | 262 | |
Antoine Pitrou | 0599b5b | 2011-11-29 22:45:07 +0100 | [diff] [blame] | 263 | Performance and resource usage |
| 264 | ------------------------------ |
| 265 | |
| 266 | The storage of Unicode strings now depends on the highest codepoint in the string: |
| 267 | |
| 268 | * pure ASCII and Latin1 strings (``U+0000-U+00FF``) use 1 byte per codepoint; |
| 269 | |
| 270 | * BMP strings (``U+0000-U+FFFF``) use 2 bytes per codepoint; |
| 271 | |
| 272 | * non-BMP strings (``U+10000-U+10FFFF``) use 4 bytes per codepoint. |
| 273 | |
Martin v. Löwis | de157cc | 2012-03-06 08:42:17 +0100 | [diff] [blame] | 274 | The net effect is that for most applications, memory usage of string |
| 275 | storage should decrease significantly - especially compared to former |
| 276 | wide unicode builds - as, in many cases, strings will be pure ASCII |
| 277 | even in international contexts (because many strings store non-human |
| 278 | language data, such as XML fragments, HTTP headers, JSON-encoded data, |
| 279 | etc.). We also hope that it will, for the same reasons, increase CPU |
| 280 | cache efficiency on non-trivial applications. The memory usage of |
| 281 | Python 3.3 is two to three times smaller than Python 3.2, and a little |
| 282 | bit better than Python 2.7, on a Django benchmark (see the PEP for |
| 283 | details). |
Antoine Pitrou | 0599b5b | 2011-11-29 22:45:07 +0100 | [diff] [blame] | 284 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 285 | .. seealso:: |
| 286 | |
| 287 | :pep:`393` - Flexible String Representation |
| 288 | PEP written by Martin von Löwis; implementation by Torsten Becker |
| 289 | and Martin von Löwis. |
| 290 | |
Éric Araujo | b07b97f | 2011-10-05 01:03:34 +0200 | [diff] [blame] | 291 | |
Nick Coghlan | 349c802 | 2012-09-30 13:00:43 +0530 | [diff] [blame] | 292 | .. _pep-397: |
| 293 | |
| 294 | PEP 397: Python Launcher for Windows |
| 295 | ==================================== |
| 296 | |
| 297 | The Python 3.3 Windows installer now includes a ``py`` launcher application |
| 298 | that can be used to launch Python applications in a version independent |
| 299 | fashion. |
| 300 | |
| 301 | This launcher is invoked implicitly when double-clicking ``*.py`` files. |
| 302 | If only a single Python version is installed on the system, that version |
| 303 | will be used to run the file. If multiple versions are installed, the most |
| 304 | recent version is used by default, but this can be overridden by including |
| 305 | a Unix-style "shebang line" in the Python script. |
| 306 | |
| 307 | The launcher can also be used explicitly from the command line as the ``py`` |
| 308 | application. Running ``py`` follows the same version selection rules as |
| 309 | implicitly launching scripts, but a more specific version can be selected |
| 310 | by passing appropriate arguments (such as ``-3`` to request Python 3 when |
| 311 | Python 2 is also installed, or ``-2.6`` to specifclly request an earlier |
| 312 | Python version when a more recent version is installed). |
| 313 | |
| 314 | In addition to the launcher, the Windows installer now includes an |
| 315 | option to add the newly installed Python to the system PATH (contributed |
Brian Curtin | f41d202 | 2012-10-01 09:29:36 -0500 | [diff] [blame] | 316 | by Brian Curtin in :issue:`3561`). |
Nick Coghlan | 349c802 | 2012-09-30 13:00:43 +0530 | [diff] [blame] | 317 | |
| 318 | .. seealso:: |
| 319 | |
| 320 | :pep:`397` - Python Launcher for Windows |
| 321 | PEP written by Mark Hammond and Martin v. Löwis; implementation by |
| 322 | Vinay Sajip. |
| 323 | |
| 324 | Launcher documentation: :ref:`launcher` |
| 325 | |
| 326 | Installer PATH modification: :ref:`windows-path-mod` |
| 327 | |
| 328 | |
Antoine Pitrou | c907de9 | 2012-08-21 00:53:06 +0200 | [diff] [blame] | 329 | .. _pep-3151: |
| 330 | |
Victor Stinner | a1bf298 | 2011-10-12 20:35:02 +0200 | [diff] [blame] | 331 | PEP 3151: Reworking the OS and IO exception hierarchy |
| 332 | ===================================================== |
| 333 | |
Antoine Pitrou | 01fd26c | 2011-10-24 00:07:02 +0200 | [diff] [blame] | 334 | The hierarchy of exceptions raised by operating system errors is now both |
| 335 | simplified and finer-grained. |
Victor Stinner | a1bf298 | 2011-10-12 20:35:02 +0200 | [diff] [blame] | 336 | |
Antoine Pitrou | 01fd26c | 2011-10-24 00:07:02 +0200 | [diff] [blame] | 337 | You don't have to worry anymore about choosing the appropriate exception |
| 338 | type between :exc:`OSError`, :exc:`IOError`, :exc:`EnvironmentError`, |
| 339 | :exc:`WindowsError`, :exc:`mmap.error`, :exc:`socket.error` or |
| 340 | :exc:`select.error`. All these exception types are now only one: |
| 341 | :exc:`OSError`. The other names are kept as aliases for compatibility |
| 342 | reasons. |
Victor Stinner | a1bf298 | 2011-10-12 20:35:02 +0200 | [diff] [blame] | 343 | |
Antoine Pitrou | 01fd26c | 2011-10-24 00:07:02 +0200 | [diff] [blame] | 344 | Also, it is now easier to catch a specific error condition. Instead of |
| 345 | inspecting the ``errno`` attribute (or ``args[0]``) for a particular |
| 346 | constant from the :mod:`errno` module, you can catch the adequate |
| 347 | :exc:`OSError` subclass. The available subclasses are the following: |
Victor Stinner | a1bf298 | 2011-10-12 20:35:02 +0200 | [diff] [blame] | 348 | |
Antoine Pitrou | 01fd26c | 2011-10-24 00:07:02 +0200 | [diff] [blame] | 349 | * :exc:`BlockingIOError` |
| 350 | * :exc:`ChildProcessError` |
| 351 | * :exc:`ConnectionError` |
| 352 | * :exc:`FileExistsError` |
| 353 | * :exc:`FileNotFoundError` |
| 354 | * :exc:`InterruptedError` |
| 355 | * :exc:`IsADirectoryError` |
| 356 | * :exc:`NotADirectoryError` |
| 357 | * :exc:`PermissionError` |
| 358 | * :exc:`ProcessLookupError` |
| 359 | * :exc:`TimeoutError` |
Victor Stinner | a1bf298 | 2011-10-12 20:35:02 +0200 | [diff] [blame] | 360 | |
Antoine Pitrou | 01fd26c | 2011-10-24 00:07:02 +0200 | [diff] [blame] | 361 | And the :exc:`ConnectionError` itself has finer-grained subclasses: |
Victor Stinner | a1bf298 | 2011-10-12 20:35:02 +0200 | [diff] [blame] | 362 | |
Antoine Pitrou | 01fd26c | 2011-10-24 00:07:02 +0200 | [diff] [blame] | 363 | * :exc:`BrokenPipeError` |
| 364 | * :exc:`ConnectionAbortedError` |
| 365 | * :exc:`ConnectionRefusedError` |
| 366 | * :exc:`ConnectionResetError` |
Victor Stinner | a1bf298 | 2011-10-12 20:35:02 +0200 | [diff] [blame] | 367 | |
| 368 | Thanks to the new exceptions, common usages of the :mod:`errno` can now be |
Antoine Pitrou | 01fd26c | 2011-10-24 00:07:02 +0200 | [diff] [blame] | 369 | avoided. For example, the following code written for Python 3.2:: |
Victor Stinner | a1bf298 | 2011-10-12 20:35:02 +0200 | [diff] [blame] | 370 | |
| 371 | from errno import ENOENT, EACCES, EPERM |
| 372 | |
| 373 | try: |
| 374 | with open("document.txt") as f: |
| 375 | content = f.read() |
| 376 | except IOError as err: |
| 377 | if err.errno == ENOENT: |
| 378 | print("document.txt file is missing") |
| 379 | elif err.errno in (EACCES, EPERM): |
| 380 | print("You are not allowed to read document.txt") |
| 381 | else: |
| 382 | raise |
| 383 | |
Antoine Pitrou | 01fd26c | 2011-10-24 00:07:02 +0200 | [diff] [blame] | 384 | can now be written without the :mod:`errno` import and without manual |
| 385 | inspection of exception attributes:: |
Victor Stinner | a1bf298 | 2011-10-12 20:35:02 +0200 | [diff] [blame] | 386 | |
| 387 | try: |
| 388 | with open("document.txt") as f: |
| 389 | content = f.read() |
| 390 | except FileNotFoundError: |
| 391 | print("document.txt file is missing") |
| 392 | except PermissionError: |
| 393 | print("You are not allowed to read document.txt") |
| 394 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 395 | .. seealso:: |
| 396 | |
| 397 | :pep:`3151` - Reworking the OS and IO Exception Hierarchy |
| 398 | PEP written and implemented by Antoine Pitrou |
| 399 | |
Victor Stinner | a1bf298 | 2011-10-12 20:35:02 +0200 | [diff] [blame] | 400 | |
Antoine Pitrou | c907de9 | 2012-08-21 00:53:06 +0200 | [diff] [blame] | 401 | .. _pep-380: |
| 402 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 403 | PEP 380: Syntax for Delegating to a Subgenerator |
| 404 | ================================================ |
| 405 | |
| 406 | PEP 380 adds the ``yield from`` expression, allowing a generator to delegate |
| 407 | part of its operations to another generator. This allows a section of code |
| 408 | containing 'yield' to be factored out and placed in another generator. |
| 409 | Additionally, the subgenerator is allowed to return with a value, and the |
| 410 | value is made available to the delegating generator. |
Nick Coghlan | b9b281b | 2012-03-06 22:31:12 +1000 | [diff] [blame] | 411 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 412 | While designed primarily for use in delegating to a subgenerator, the ``yield |
| 413 | from`` expression actually allows delegation to arbitrary subiterators. |
| 414 | |
Nick Coghlan | b9b281b | 2012-03-06 22:31:12 +1000 | [diff] [blame] | 415 | For simple iterators, ``yield from iterable`` is essentially just a shortened |
| 416 | form of ``for item in iterable: yield item``:: |
| 417 | |
| 418 | >>> def g(x): |
| 419 | ... yield from range(x, 0, -1) |
| 420 | ... yield from range(x) |
| 421 | ... |
| 422 | >>> list(g(5)) |
| 423 | [5, 4, 3, 2, 1, 0, 1, 2, 3, 4] |
| 424 | |
| 425 | However, unlike an ordinary loop, ``yield from`` allows subgenerators to |
| 426 | receive sent and thrown values directly from the calling scope, and |
| 427 | return a final value to the outer generator:: |
| 428 | |
| 429 | >>> def accumulate(start=0): |
| 430 | ... tally = start |
| 431 | ... while 1: |
| 432 | ... next = yield |
| 433 | ... if next is None: |
| 434 | ... return tally |
| 435 | ... tally += next |
| 436 | ... |
| 437 | >>> def gather_tallies(tallies, start=0): |
| 438 | ... while 1: |
| 439 | ... tally = yield from accumulate() |
| 440 | ... tallies.append(tally) |
| 441 | ... |
| 442 | >>> tallies = [] |
| 443 | >>> acc = gather_tallies(tallies) |
| 444 | >>> next(acc) # Ensure the accumulator is ready to accept values |
| 445 | >>> for i in range(10): |
| 446 | ... acc.send(i) |
| 447 | ... |
| 448 | >>> acc.send(None) # Finish the first tally |
| 449 | >>> for i in range(5): |
| 450 | ... acc.send(i) |
| 451 | ... |
| 452 | >>> acc.send(None) # Finish the second tally |
| 453 | >>> tallies |
| 454 | [45, 10] |
| 455 | |
| 456 | The main principle driving this change is to allow even generators that are |
| 457 | designed to be used with the ``send`` and ``throw`` methods to be split into |
| 458 | multiple subgenerators as easily as a single large function can be split into |
| 459 | multiple subfunctions. |
| 460 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 461 | .. seealso:: |
| 462 | |
| 463 | :pep:`380` - Syntax for Delegating to a Subgenerator |
| 464 | PEP written by Greg Ewing; implementation by Greg Ewing, integrated into |
| 465 | 3.3 by Renaud Blanch, Ryan Kelly and Nick Coghlan, documentation by |
| 466 | Zbigniew Jędrzejewski-Szmek and Nick Coghlan) |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 467 | |
| 468 | |
Nick Coghlan | ab7bf21 | 2012-02-26 17:49:52 +1000 | [diff] [blame] | 469 | PEP 409: Suppressing exception context |
| 470 | ====================================== |
| 471 | |
Nick Coghlan | ab7bf21 | 2012-02-26 17:49:52 +1000 | [diff] [blame] | 472 | PEP 409 introduces new syntax that allows the display of the chained |
| 473 | exception context to be disabled. This allows cleaner error messages in |
| 474 | applications that convert between exception types:: |
| 475 | |
| 476 | >>> class D: |
| 477 | ... def __init__(self, extra): |
| 478 | ... self._extra_attributes = extra |
| 479 | ... def __getattr__(self, attr): |
| 480 | ... try: |
| 481 | ... return self._extra_attributes[attr] |
| 482 | ... except KeyError: |
| 483 | ... raise AttributeError(attr) from None |
| 484 | ... |
| 485 | >>> D({}).x |
| 486 | Traceback (most recent call last): |
| 487 | File "<stdin>", line 1, in <module> |
| 488 | File "<stdin>", line 8, in __getattr__ |
| 489 | AttributeError: x |
| 490 | |
| 491 | Without the ``from None`` suffix to suppress the cause, the original |
| 492 | exception would be displayed by default:: |
| 493 | |
| 494 | >>> class C: |
| 495 | ... def __init__(self, extra): |
| 496 | ... self._extra_attributes = extra |
| 497 | ... def __getattr__(self, attr): |
| 498 | ... try: |
| 499 | ... return self._extra_attributes[attr] |
| 500 | ... except KeyError: |
| 501 | ... raise AttributeError(attr) |
| 502 | ... |
| 503 | >>> C({}).x |
| 504 | Traceback (most recent call last): |
| 505 | File "<stdin>", line 6, in __getattr__ |
| 506 | KeyError: 'x' |
| 507 | |
| 508 | During handling of the above exception, another exception occurred: |
| 509 | |
| 510 | Traceback (most recent call last): |
| 511 | File "<stdin>", line 1, in <module> |
| 512 | File "<stdin>", line 8, in __getattr__ |
| 513 | AttributeError: x |
| 514 | |
| 515 | No debugging capability is lost, as the original exception context remains |
| 516 | available if needed (for example, if an intervening library has incorrectly |
| 517 | suppressed valuable underlying details):: |
| 518 | |
| 519 | >>> try: |
| 520 | ... D({}).x |
| 521 | ... except AttributeError as exc: |
| 522 | ... print(repr(exc.__context__)) |
| 523 | ... |
| 524 | KeyError('x',) |
| 525 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 526 | .. seealso:: |
| 527 | |
| 528 | :pep:`409` - Suppressing exception context |
| 529 | PEP written by Ethan Furman; implemented by Ethan Furman and Nick |
| 530 | Coghlan. |
| 531 | |
Nick Coghlan | ab7bf21 | 2012-02-26 17:49:52 +1000 | [diff] [blame] | 532 | |
Nick Coghlan | 98e2070 | 2012-03-06 21:50:13 +1000 | [diff] [blame] | 533 | PEP 414: Explicit Unicode literals |
| 534 | ====================================== |
| 535 | |
Nick Coghlan | 98e2070 | 2012-03-06 21:50:13 +1000 | [diff] [blame] | 536 | To ease the transition from Python 2 for Unicode aware Python applications |
| 537 | that make heavy use of Unicode literals, Python 3.3 once again supports the |
| 538 | "``u``" prefix for string literals. This prefix has no semantic significance |
| 539 | in Python 3, it is provided solely to reduce the number of purely mechanical |
| 540 | changes in migrating to Python 3, making it easier for developers to focus on |
| 541 | the more significant semantic changes (such as the stricter default |
| 542 | separation of binary and text data). |
| 543 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 544 | .. seealso:: |
| 545 | |
| 546 | :pep:`414` - Explicit Unicode literals |
| 547 | PEP written by Armin Ronacher. |
| 548 | |
Nick Coghlan | 98e2070 | 2012-03-06 21:50:13 +1000 | [diff] [blame] | 549 | |
Antoine Pitrou | 6bbd76b | 2011-11-25 19:10:05 +0100 | [diff] [blame] | 550 | PEP 3155: Qualified name for classes and functions |
| 551 | ================================================== |
| 552 | |
Antoine Pitrou | 6bbd76b | 2011-11-25 19:10:05 +0100 | [diff] [blame] | 553 | Functions and class objects have a new ``__qualname__`` attribute representing |
| 554 | the "path" from the module top-level to their definition. For global functions |
| 555 | and classes, this is the same as ``__name__``. For other functions and classes, |
| 556 | it provides better information about where they were actually defined, and |
| 557 | how they might be accessible from the global scope. |
| 558 | |
| 559 | Example with (non-bound) methods:: |
Nick Coghlan | 2dfe6b0 | 2012-01-14 14:19:49 +1000 | [diff] [blame] | 560 | |
Antoine Pitrou | 6bbd76b | 2011-11-25 19:10:05 +0100 | [diff] [blame] | 561 | >>> class C: |
| 562 | ... def meth(self): |
| 563 | ... pass |
| 564 | >>> C.meth.__name__ |
| 565 | 'meth' |
| 566 | >>> C.meth.__qualname__ |
| 567 | 'C.meth' |
| 568 | |
| 569 | Example with nested classes:: |
| 570 | |
| 571 | >>> class C: |
| 572 | ... class D: |
| 573 | ... def meth(self): |
| 574 | ... pass |
| 575 | ... |
| 576 | >>> C.D.__name__ |
| 577 | 'D' |
| 578 | >>> C.D.__qualname__ |
| 579 | 'C.D' |
| 580 | >>> C.D.meth.__name__ |
| 581 | 'meth' |
| 582 | >>> C.D.meth.__qualname__ |
| 583 | 'C.D.meth' |
| 584 | |
| 585 | Example with nested functions:: |
| 586 | |
| 587 | >>> def outer(): |
| 588 | ... def inner(): |
| 589 | ... pass |
| 590 | ... return inner |
| 591 | ... |
| 592 | >>> outer().__name__ |
| 593 | 'inner' |
| 594 | >>> outer().__qualname__ |
| 595 | 'outer.<locals>.inner' |
| 596 | |
Antoine Pitrou | e7ede06 | 2011-11-25 19:11:26 +0100 | [diff] [blame] | 597 | The string representation of those objects is also changed to include the |
Antoine Pitrou | 6bbd76b | 2011-11-25 19:10:05 +0100 | [diff] [blame] | 598 | new, more precise information:: |
| 599 | |
| 600 | >>> str(C.D) |
| 601 | "<class '__main__.C.D'>" |
| 602 | >>> str(C.D.meth) |
| 603 | '<function C.D.meth at 0x7f46b9fe31e0>' |
| 604 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 605 | .. seealso:: |
| 606 | |
| 607 | :pep:`3155` - Qualified name for classes and functions |
| 608 | PEP written and implemented by Antoine Pitrou. |
| 609 | |
Antoine Pitrou | 6bbd76b | 2011-11-25 19:10:05 +0100 | [diff] [blame] | 610 | |
Antoine Pitrou | c907de9 | 2012-08-21 00:53:06 +0200 | [diff] [blame] | 611 | .. _pep-412: |
| 612 | |
Antoine Pitrou | d94adb7 | 2012-07-07 17:33:42 +0200 | [diff] [blame] | 613 | PEP 412: Key-Sharing Dictionary |
| 614 | =============================== |
| 615 | |
Antoine Pitrou | d94adb7 | 2012-07-07 17:33:42 +0200 | [diff] [blame] | 616 | Dictionaries used for the storage of objects' attributes are now able to |
| 617 | share part of their internal storage between each other (namely, the part |
| 618 | which stores the keys and their respective hashes). This reduces the memory |
| 619 | consumption of programs creating many instances of non-builtin types. |
| 620 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 621 | .. seealso:: |
| 622 | |
| 623 | :pep:`412` - Key-Sharing Dictionary |
| 624 | PEP written and implemented by Mark Shannon. |
| 625 | |
Antoine Pitrou | d94adb7 | 2012-07-07 17:33:42 +0200 | [diff] [blame] | 626 | |
Andrew Svetlov | ac23c9e | 2012-08-13 21:27:56 +0300 | [diff] [blame] | 627 | PEP 362: Function Signature Object |
| 628 | ================================== |
| 629 | |
Andrew Svetlov | ac23c9e | 2012-08-13 21:27:56 +0300 | [diff] [blame] | 630 | A new function :func:`inspect.signature` makes introspection of python |
| 631 | callables easy and straightforward. A broad range of callables is supported: |
| 632 | python functions, decorated or not, classes, and :func:`functools.partial` |
| 633 | objects. New classes :class:`inspect.Signature`, :class:`inspect.Parameter` |
| 634 | and :class:`inspect.BoundArguments` hold information about the call signatures, |
| 635 | such as, annotations, default values, parameters kinds, and bound arguments, |
| 636 | which considerably simplifies writing decorators and any code that validates |
| 637 | or amends calling signatures or arguments. |
| 638 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 639 | .. seealso:: |
| 640 | |
| 641 | :pep:`362`: - Function Signature Object |
| 642 | PEP written by Brett Cannon, Yury Selivanov, Larry Hastings, Jiwon Seo; |
| 643 | implemented by Yury Selivanov. |
| 644 | |
Andrew Svetlov | ac23c9e | 2012-08-13 21:27:56 +0300 | [diff] [blame] | 645 | |
Eric Snow | b2a61e1 | 2012-09-05 22:19:38 -0700 | [diff] [blame] | 646 | PEP 421: Adding sys.implementation |
| 647 | ================================== |
| 648 | |
Eric Snow | b2a61e1 | 2012-09-05 22:19:38 -0700 | [diff] [blame] | 649 | A new attribute on the :mod:`sys` module exposes details specific to the |
| 650 | implementation of the currently running interpreter. The initial set of |
| 651 | attributes on :attr:`sys.implementation` are ``name``, ``version``, |
| 652 | ``hexversion``, and ``cache_tag``. |
| 653 | |
| 654 | The intention of ``sys.implementation`` is to consolidate into one namespace |
| 655 | the implementation-specific data used by the standard library. This allows |
| 656 | different Python implementations to share a single standard library code base |
| 657 | much more easily. In its initial state, ``sys.implementation`` holds only a |
| 658 | small portion of the implementation-specific data. Over time that ratio will |
| 659 | shift in order to make the standard library more portable. |
| 660 | |
| 661 | One example of improved standard library portability is ``cache_tag``. As of |
| 662 | Python 3.3, ``sys.implementation.cache_tag`` is used by :mod:`importlib` to |
| 663 | support :pep:`3147` compliance. Any Python implementation that uses |
| 664 | ``importlib`` for its built-in import system may use ``cache_tag`` to control |
| 665 | the caching behavior for modules. |
| 666 | |
| 667 | SimpleNamespace |
| 668 | --------------- |
| 669 | |
| 670 | The implementation of ``sys.implementation`` also introduces a new type to |
| 671 | Python: :class:`types.SimpleNamespace`. In contrast to a mapping-based |
| 672 | namespace, like :class:`dict`, ``SimpleNamespace`` is attribute-based, like |
| 673 | :class:`object`. However, unlike ``object``, ``SimpleNamespace`` instances |
| 674 | are writable. This means that you can add, remove, and modify the namespace |
| 675 | through normal attribute access. |
| 676 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 677 | .. seealso:: |
| 678 | |
| 679 | :pep:`421` - Adding sys.implementation |
| 680 | PEP written and implemented by Eric Snow. |
| 681 | |
Eric Snow | b2a61e1 | 2012-09-05 22:19:38 -0700 | [diff] [blame] | 682 | |
Antoine Pitrou | c907de9 | 2012-08-21 00:53:06 +0200 | [diff] [blame] | 683 | .. _importlib: |
| 684 | |
Brett Cannon | c204348 | 2012-04-29 20:59:41 -0400 | [diff] [blame] | 685 | Using importlib as the Implementation of Import |
| 686 | =============================================== |
| 687 | :issue:`2377` - Replace __import__ w/ importlib.__import__ |
| 688 | :issue:`13959` - Re-implement parts of :mod:`imp` in pure Python |
| 689 | :issue:`14605` - Make import machinery explicit |
| 690 | :issue:`14646` - Require loaders set __loader__ and __package__ |
| 691 | |
Brett Cannon | c204348 | 2012-04-29 20:59:41 -0400 | [diff] [blame] | 692 | The :func:`__import__` function is now powered by :func:`importlib.__import__`. |
| 693 | This work leads to the completion of "phase 2" of :pep:`302`. There are |
| 694 | multiple benefits to this change. First, it has allowed for more of the |
| 695 | machinery powering import to be exposed instead of being implicit and hidden |
| 696 | within the C code. It also provides a single implementation for all Python VMs |
| 697 | supporting Python 3.3 to use, helping to end any VM-specific deviations in |
| 698 | import semantics. And finally it eases the maintenance of import, allowing for |
| 699 | future growth to occur. |
| 700 | |
R David Murray | cff1c6f | 2012-09-29 14:34:43 -0400 | [diff] [blame] | 701 | For the common user, there should be no visible change in semantics. For |
| 702 | those whose code currently manipulates import or calls import |
| 703 | programmatically, the code changes that might possibly be required are covered |
| 704 | in the `Porting Python code`_ section of this document. |
Brett Cannon | c204348 | 2012-04-29 20:59:41 -0400 | [diff] [blame] | 705 | |
| 706 | New APIs |
| 707 | -------- |
| 708 | One of the large benefits of this work is the exposure of what goes into |
| 709 | making the import statement work. That means the various importers that were |
| 710 | once implicit are now fully exposed as part of the :mod:`importlib` package. |
| 711 | |
Brett Cannon | 077ef45 | 2012-08-02 17:50:06 -0400 | [diff] [blame] | 712 | The abstract base classes defined in :mod:`importlib.abc` have been expanded |
| 713 | to properly delineate between :term:`meta path finders <meta path finder>` |
| 714 | and :term:`path entry finders <path entry finder>` by introducing |
| 715 | :class:`importlib.abc.MetaPathFinder` and |
| 716 | :class:`importlib.abc.PathEntryFinder`, respectively. The old ABC of |
| 717 | :class:`importlib.abc.Finder` is now only provided for backwards-compatibility |
| 718 | and does not enforce any method requirements. |
| 719 | |
| 720 | In terms of finders, :class:`importlib.machinery.FileFinder` exposes the |
Brett Cannon | c204348 | 2012-04-29 20:59:41 -0400 | [diff] [blame] | 721 | mechanism used to search for source and bytecode files of a module. Previously |
| 722 | this class was an implicit member of :attr:`sys.path_hooks`. |
| 723 | |
| 724 | For loaders, the new abstract base class :class:`importlib.abc.FileLoader` helps |
| 725 | write a loader that uses the file system as the storage mechanism for a module's |
| 726 | code. The loader for source files |
| 727 | (:class:`importlib.machinery.SourceFileLoader`), sourceless bytecode files |
| 728 | (:class:`importlib.machinery.SourcelessFileLoader`), and extension modules |
| 729 | (:class:`importlib.machinery.ExtensionFileLoader`) are now available for |
| 730 | direct use. |
| 731 | |
| 732 | :exc:`ImportError` now has ``name`` and ``path`` attributes which are set when |
| 733 | there is relevant data to provide. The message for failed imports will also |
| 734 | provide the full name of the module now instead of just the tail end of the |
| 735 | module's name. |
| 736 | |
| 737 | The :func:`importlib.invalidate_caches` function will now call the method with |
| 738 | the same name on all finders cached in :attr:`sys.path_importer_cache` to help |
| 739 | clean up any stored state as necessary. |
| 740 | |
| 741 | Visible Changes |
| 742 | --------------- |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 743 | |
| 744 | For potential required changes to code, see the `Porting Python code`_ |
| 745 | section. |
Brett Cannon | c204348 | 2012-04-29 20:59:41 -0400 | [diff] [blame] | 746 | |
| 747 | Beyond the expanse of what :mod:`importlib` now exposes, there are other |
| 748 | visible changes to import. The biggest is that :attr:`sys.meta_path` and |
Brett Cannon | 077ef45 | 2012-08-02 17:50:06 -0400 | [diff] [blame] | 749 | :attr:`sys.path_hooks` now store all of the meta path finders and path entry |
| 750 | hooks used by import. Previously the finders were implicit and hidden within |
| 751 | the C code of import instead of being directly exposed. This means that one can |
| 752 | now easily remove or change the order of the various finders to fit one's needs. |
Brett Cannon | c204348 | 2012-04-29 20:59:41 -0400 | [diff] [blame] | 753 | |
| 754 | Another change is that all modules have a ``__loader__`` attribute, storing the |
| 755 | loader used to create the module. :pep:`302` has been updated to make this |
| 756 | attribute mandatory for loaders to implement, so in the future once 3rd-party |
| 757 | loaders have been updated people will be able to rely on the existence of the |
| 758 | attribute. Until such time, though, import is setting the module post-load. |
| 759 | |
| 760 | Loaders are also now expected to set the ``__package__`` attribute from |
| 761 | :pep:`366`. Once again, import itself is already setting this on all loaders |
| 762 | from :mod:`importlib` and import itself is setting the attribute post-load. |
| 763 | |
| 764 | ``None`` is now inserted into :attr:`sys.path_importer_cache` when no finder |
| 765 | can be found on :attr:`sys.path_hooks`. Since :class:`imp.NullImporter` is not |
| 766 | directly exposed on :attr:`sys.path_hooks` it could no longer be relied upon to |
| 767 | always be available to use as a value representing no finder found. |
| 768 | |
| 769 | All other changes relate to semantic changes which should be taken into |
| 770 | consideration when updating code for Python 3.3, and thus should be read about |
| 771 | in the `Porting Python code`_ section of this document. |
| 772 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 773 | (Implementation by Brett Cannon) |
| 774 | |
Brett Cannon | c204348 | 2012-04-29 20:59:41 -0400 | [diff] [blame] | 775 | |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 776 | Other Language Changes |
| 777 | ====================== |
| 778 | |
| 779 | Some smaller changes made to the core Python language are: |
| 780 | |
Antoine Pitrou | 7b578b3 | 2011-11-29 22:47:11 +0100 | [diff] [blame] | 781 | * Added support for Unicode name aliases and named sequences. |
| 782 | Both :func:`unicodedata.lookup()` and ``'\N{...}'`` now resolve name aliases, |
| 783 | and :func:`unicodedata.lookup()` resolves named sequences too. |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 784 | |
Antoine Pitrou | 7b578b3 | 2011-11-29 22:47:11 +0100 | [diff] [blame] | 785 | (Contributed by Ezio Melotti in :issue:`12753`) |
Ezio Melotti | 931b8aa | 2011-10-21 21:57:36 +0300 | [diff] [blame] | 786 | |
Nick Coghlan | c4bacd3 | 2012-09-27 19:58:31 +1000 | [diff] [blame] | 787 | * Unicode database updated to UCD version 6.1.0 |
| 788 | |
Antoine Pitrou | 7b578b3 | 2011-11-29 22:47:11 +0100 | [diff] [blame] | 789 | * Equality comparisons on :func:`range` objects now return a result reflecting |
| 790 | the equality of the underlying sequences generated by those range objects. |
Sandro Tosi | cd89912 | 2012-01-22 12:16:04 +0100 | [diff] [blame] | 791 | (:issue:`13201`) |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 792 | |
Antoine Pitrou | 7b578b3 | 2011-11-29 22:47:11 +0100 | [diff] [blame] | 793 | * The ``count()``, ``find()``, ``rfind()``, ``index()`` and ``rindex()`` |
| 794 | methods of :class:`bytes` and :class:`bytearray` objects now accept an |
| 795 | integer between 0 and 255 as their first argument. |
Mark Dickinson | 3664568 | 2011-10-23 19:53:01 +0100 | [diff] [blame] | 796 | |
Petri Lehtinen | 6c3f1dd | 2012-06-26 10:23:07 +0300 | [diff] [blame] | 797 | (Contributed by Petri Lehtinen in :issue:`12170`) |
Mark Dickinson | 3664568 | 2011-10-23 19:53:01 +0100 | [diff] [blame] | 798 | |
Eli Bendersky | 7add4ea | 2012-03-17 15:14:35 +0200 | [diff] [blame] | 799 | * New methods have been added to :class:`list` and :class:`bytearray`: |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 800 | ``copy()`` and ``clear()`` (:issue:`10516`). Consequently, |
| 801 | :class:`~collections.abc.MutableSequence` now also defines a |
| 802 | :meth:`~collections.abc.MutableSequence.clear` method (:issue:`11388`). |
Petri Lehtinen | 61ea8a0 | 2011-11-24 22:00:46 +0200 | [diff] [blame] | 803 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 804 | * Raw bytes literals can now be written ``rb"..."`` as well as ``br"..."``. |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 805 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 806 | (Contributed by Antoine Pitrou in :issue:`13748`.) |
| 807 | |
| 808 | * :meth:`dict.setdefault` now does only one lookup for the given key, making |
| 809 | it atomic when used with built-in types. |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 810 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 811 | (Contributed by Filip Gruszczyński in :issue:`13521`.) |
| 812 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 813 | * The error messages produced when a function call does not match the function |
| 814 | signature have been significantly improved. |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 815 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 816 | (Contributed by Benjamin Peterson.) |
Benjamin Peterson | e50d6ab | 2012-04-03 00:52:18 -0400 | [diff] [blame] | 817 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 818 | |
Antoine Pitrou | 79341e7 | 2012-05-17 21:13:45 +0200 | [diff] [blame] | 819 | A Finer-Grained Import Lock |
| 820 | =========================== |
| 821 | |
| 822 | Previous versions of CPython have always relied on a global import lock. |
| 823 | This led to unexpected annoyances, such as deadlocks when importing a module |
| 824 | would trigger code execution in a different thread as a side-effect. |
| 825 | Clumsy workarounds were sometimes employed, such as the |
| 826 | :c:func:`PyImport_ImportModuleNoBlock` C API function. |
| 827 | |
| 828 | In Python 3.3, importing a module takes a per-module lock. This correctly |
| 829 | serializes importation of a given module from multiple threads (preventing |
| 830 | the exposure of incompletely initialized modules), while eliminating the |
| 831 | aforementioned annoyances. |
| 832 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 833 | (Contributed by Antoine Pitrou in :issue:`9260`.) |
Antoine Pitrou | 79341e7 | 2012-05-17 21:13:45 +0200 | [diff] [blame] | 834 | |
| 835 | |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 836 | Builtin functions and types |
| 837 | =========================== |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 838 | |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 839 | * :func:`open` gets a new *opener* parameter: the underlying file descriptor |
| 840 | for the file object is then obtained by calling *opener* with (*file*, |
| 841 | *flags*). It can be used to use custom flags like :data:`os.O_CLOEXEC` for |
| 842 | example. The ``'x'`` mode was added: open for exclusive creation, failing if |
| 843 | the file already exists. |
| 844 | * :func:`print`: added the *flush* keyword argument. If the *flush* keyword |
| 845 | argument is true, the stream is forcibly flushed. |
| 846 | * :func:`hash`: hash randomization is enabled by default, see |
| 847 | :meth:`object.__hash__` and :envvar:`PYTHONHASHSEED`. |
| 848 | * The :class:`str` type gets a new :meth:`~str.casefold` method: return a |
| 849 | casefolded copy of the string, casefolded strings may be used for caseless |
| 850 | matching. For example, ``'ß'.casefold()`` returns ``'ss'``. |
Nick Coghlan | 273069c | 2012-08-20 17:14:07 +1000 | [diff] [blame] | 851 | * The sequence documentation has been substantially rewritten to better |
| 852 | explain the binary/text sequence distinction and to provide specific |
| 853 | documentation sections for the individual builtin sequence types |
| 854 | (:issue:`4966`) |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 855 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 856 | |
Victor Stinner | 636130e | 2012-08-05 16:37:12 +0200 | [diff] [blame] | 857 | New Modules |
| 858 | =========== |
| 859 | |
| 860 | faulthandler |
| 861 | ------------ |
| 862 | |
Victor Stinner | 1da769a | 2012-09-18 22:40:03 +0200 | [diff] [blame] | 863 | This new debug module :mod:`faulthandler` contains functions to dump Python tracebacks explicitly, |
Victor Stinner | 636130e | 2012-08-05 16:37:12 +0200 | [diff] [blame] | 864 | on a fault (a crash like a segmentation fault), after a timeout, or on a user |
| 865 | signal. Call :func:`faulthandler.enable` to install fault handlers for the |
| 866 | :const:`SIGSEGV`, :const:`SIGFPE`, :const:`SIGABRT`, :const:`SIGBUS`, and |
| 867 | :const:`SIGILL` signals. You can also enable them at startup by setting the |
| 868 | :envvar:`PYTHONFAULTHANDLER` environment variable or by using :option:`-X` |
| 869 | ``faulthandler`` command line option. |
| 870 | |
| 871 | Example of a segmentation fault on Linux: :: |
| 872 | |
| 873 | $ python -q -X faulthandler |
| 874 | >>> import ctypes |
| 875 | >>> ctypes.string_at(0) |
| 876 | Fatal Python error: Segmentation fault |
| 877 | |
| 878 | Current thread 0x00007fb899f39700: |
| 879 | File "/home/python/cpython/Lib/ctypes/__init__.py", line 486 in string_at |
| 880 | File "<stdin>", line 1 in <module> |
| 881 | Segmentation fault |
| 882 | |
| 883 | |
| 884 | ipaddress |
| 885 | --------- |
| 886 | |
| 887 | The new :mod:`ipaddress` module provides tools for creating and manipulating |
| 888 | objects representing IPv4 and IPv6 addresses, networks and interfaces (i.e. |
| 889 | an IP address associated with a specific IP subnet). |
| 890 | |
| 891 | (Contributed by Google and Peter Moody in :pep:`3144`) |
| 892 | |
| 893 | lzma |
| 894 | ---- |
| 895 | |
| 896 | The newly-added :mod:`lzma` module provides data compression and decompression |
| 897 | using the LZMA algorithm, including support for the ``.xz`` and ``.lzma`` |
| 898 | file formats. |
| 899 | |
| 900 | (Contributed by Nadeem Vawda and Per Øyvind Karlsen in :issue:`6715`) |
| 901 | |
| 902 | |
| 903 | Improved Modules |
| 904 | ================ |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 905 | |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 906 | abc |
| 907 | --- |
| 908 | |
| 909 | Improved support for abstract base classes containing descriptors composed with |
| 910 | abstract methods. The recommended approach to declaring abstract descriptors is |
| 911 | now to provide :attr:`__isabstractmethod__` as a dynamically updated |
| 912 | property. The built-in descriptors have been updated accordingly. |
| 913 | |
| 914 | * :class:`abc.abstractproperty` has been deprecated, use :class:`property` |
| 915 | with :func:`abc.abstractmethod` instead. |
| 916 | * :class:`abc.abstractclassmethod` has been deprecated, use |
| 917 | :class:`classmethod` with :func:`abc.abstractmethod` instead. |
| 918 | * :class:`abc.abstractstaticmethod` has been deprecated, use |
| 919 | :class:`staticmethod` with :func:`abc.abstractmethod` instead. |
| 920 | |
| 921 | (Contributed by Darren Dale in :issue:`11610`) |
| 922 | |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 923 | :meth:`abc.ABCMeta.register` now returns the registered subclass, which means |
| 924 | it can now be used as a class decorator (:issue:`10868`). |
| 925 | |
| 926 | |
Meador Inge | c5dbb3d | 2011-09-20 21:48:16 -0500 | [diff] [blame] | 927 | array |
| 928 | ----- |
| 929 | |
| 930 | The :mod:`array` module supports the :c:type:`long long` type using ``q`` and |
| 931 | ``Q`` type codes. |
| 932 | |
| 933 | (Contributed by Oren Tirosh and Hirokazu Yamamoto in :issue:`1172711`) |
| 934 | |
| 935 | |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 936 | base64, binascii |
| 937 | ---------------- |
| 938 | |
| 939 | ASCII-only Unicode strings are now accepted by the decoding functions of the |
| 940 | modern interface. For example, ``base64.b64decode('YWJj')`` returns ``b'abc'``. |
| 941 | |
| 942 | |
R David Murray | fd74096 | 2012-10-06 22:08:08 -0400 | [diff] [blame] | 943 | binascii |
| 944 | -------- |
| 945 | |
| 946 | In addition to the binary objects they normally accept, the ``a2b_`` functions |
| 947 | now all also accept ASCII-only strings as input. (Contributed by Antoine |
| 948 | Pitrou in :issue:`13637`.) |
| 949 | |
| 950 | |
Nadeem Vawda | d7e5c6e | 2012-02-12 01:34:18 +0200 | [diff] [blame] | 951 | bz2 |
| 952 | --- |
| 953 | |
| 954 | The :mod:`bz2` module has been rewritten from scratch. In the process, several |
| 955 | new features have been added: |
| 956 | |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 957 | * New :func:`bz2.open` function: open a bzip2-compressed file in binary or |
| 958 | text mode. |
| 959 | |
Nadeem Vawda | d7e5c6e | 2012-02-12 01:34:18 +0200 | [diff] [blame] | 960 | * :class:`bz2.BZ2File` can now read from and write to arbitrary file-like |
| 961 | objects, by means of its constructor's *fileobj* argument. |
| 962 | |
| 963 | (Contributed by Nadeem Vawda in :issue:`5863`) |
| 964 | |
| 965 | * :class:`bz2.BZ2File` and :func:`bz2.decompress` can now decompress |
| 966 | multi-stream inputs (such as those produced by the :program:`pbzip2` tool). |
| 967 | :class:`bz2.BZ2File` can now also be used to create this type of file, using |
| 968 | the ``'a'`` (append) mode. |
| 969 | |
| 970 | (Contributed by Nir Aides in :issue:`1625`) |
| 971 | |
| 972 | * :class:`bz2.BZ2File` now implements all of the :class:`io.BufferedIOBase` API, |
| 973 | except for the :meth:`detach` and :meth:`truncate` methods. |
| 974 | |
| 975 | |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 976 | codecs |
| 977 | ------ |
| 978 | |
Antoine Pitrou | 4f86343 | 2012-02-12 02:12:47 +0100 | [diff] [blame] | 979 | The :mod:`~encodings.mbcs` codec has been rewritten to handle correctly |
Georg Brandl | ff962c5 | 2012-02-04 08:55:56 +0100 | [diff] [blame] | 980 | ``replace`` and ``ignore`` error handlers on all Windows versions. The |
| 981 | :mod:`~encodings.mbcs` codec now supports all error handlers, instead of only |
| 982 | ``replace`` to encode and ``ignore`` to decode. |
Victor Stinner | 3a50e70 | 2011-10-18 21:21:00 +0200 | [diff] [blame] | 983 | |
Georg Brandl | ff962c5 | 2012-02-04 08:55:56 +0100 | [diff] [blame] | 984 | A new Windows-only codec has been added: ``cp65001`` (:issue:`13216`). It is the |
| 985 | Windows code page 65001 (Windows UTF-8, ``CP_UTF8``). For example, it is used |
| 986 | by ``sys.stdout`` if the console output code page is set to cp65001 (e.g., using |
| 987 | ``chcp 65001`` command). |
Victor Stinner | 2f3ca9f | 2011-10-27 01:38:56 +0200 | [diff] [blame] | 988 | |
Georg Brandl | ff962c5 | 2012-02-04 08:55:56 +0100 | [diff] [blame] | 989 | Multibyte CJK decoders now resynchronize faster. They only ignore the first |
Georg Brandl | 6c0929b | 2011-07-09 11:43:33 +0200 | [diff] [blame] | 990 | byte of an invalid byte sequence. For example, ``b'\xff\n'.decode('gb2312', |
| 991 | 'replace')`` now returns a ``\n`` after the replacement character. |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 992 | |
Georg Brandl | 6c0929b | 2011-07-09 11:43:33 +0200 | [diff] [blame] | 993 | (:issue:`12016`) |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 994 | |
Georg Brandl | ff962c5 | 2012-02-04 08:55:56 +0100 | [diff] [blame] | 995 | Incremental CJK codec encoders are no longer reset at each call to their |
| 996 | encode() methods. For example:: |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 997 | |
| 998 | $ ./python -q |
| 999 | >>> import codecs |
| 1000 | >>> encoder = codecs.getincrementalencoder('hz')('strict') |
| 1001 | >>> b''.join(encoder.encode(x) for x in '\u52ff\u65bd\u65bc\u4eba\u3002 Bye.') |
| 1002 | b'~{NpJ)l6HK!#~} Bye.' |
| 1003 | |
Georg Brandl | 6c0929b | 2011-07-09 11:43:33 +0200 | [diff] [blame] | 1004 | This example gives ``b'~{Np~}~{J)~}~{l6~}~{HK~}~{!#~} Bye.'`` with older Python |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 1005 | versions. |
| 1006 | |
Georg Brandl | 6c0929b | 2011-07-09 11:43:33 +0200 | [diff] [blame] | 1007 | (:issue:`12100`) |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 1008 | |
Victor Stinner | 9f4b1e9 | 2011-11-10 20:56:30 +0100 | [diff] [blame] | 1009 | The ``unicode_internal`` codec has been deprecated. |
| 1010 | |
Éric Araujo | 4f61a2d | 2012-04-04 23:01:01 -0400 | [diff] [blame] | 1011 | |
| 1012 | collections |
| 1013 | ----------- |
| 1014 | |
| 1015 | Addition of a new :class:`~collections.ChainMap` class to allow treating a |
R David Murray | a21e515 | 2012-10-06 16:29:14 -0400 | [diff] [blame] | 1016 | number of mappings as a single unit. (Written by Raymond Hettinger for |
| 1017 | :issue:`11089`, made public in :issue:`11297`) |
Éric Araujo | 4f61a2d | 2012-04-04 23:01:01 -0400 | [diff] [blame] | 1018 | |
| 1019 | The abstract base classes have been moved in a new :mod:`collections.abc` |
| 1020 | module, to better differentiate between the abstract and the concrete |
| 1021 | collections classes. Aliases for ABCs are still present in the |
R David Murray | a21e515 | 2012-10-06 16:29:14 -0400 | [diff] [blame] | 1022 | :mod:`collections` module to preserve existing imports. (:issue:`11085`) |
Éric Araujo | 4f61a2d | 2012-04-04 23:01:01 -0400 | [diff] [blame] | 1023 | |
| 1024 | .. XXX addition of __slots__ to ABCs not recorded here: internal detail |
| 1025 | |
R David Murray | a21e515 | 2012-10-06 16:29:14 -0400 | [diff] [blame] | 1026 | The :class:`~collections.Counter` class now supports the unary ``+`` and ``-`` |
| 1027 | operators, as well as the in-place operators ``+=``, ``-=``, ``|=``, and |
| 1028 | ``&=``. (Contributed by Raymond Hettinger in :issue:`13121`.) |
| 1029 | |
Éric Araujo | 4f61a2d | 2012-04-04 23:01:01 -0400 | [diff] [blame] | 1030 | |
Nick Coghlan | 3267a30 | 2012-05-21 22:54:43 +1000 | [diff] [blame] | 1031 | contextlib |
| 1032 | ---------- |
| 1033 | |
Giampaolo Rodola' | 15c8849 | 2012-09-25 12:00:04 -0700 | [diff] [blame] | 1034 | :class:`~contextlib.ExitStack` now provides a solid foundation for |
Nick Coghlan | 3267a30 | 2012-05-21 22:54:43 +1000 | [diff] [blame] | 1035 | programmatic manipulation of context managers and similar cleanup |
| 1036 | functionality. Unlike the previous ``contextlib.nested`` API (which was |
| 1037 | deprecated and removed), the new API is designed to work correctly |
| 1038 | regardless of whether context managers acquire their resources in |
Nick Coghlan | 161ea6a | 2012-05-22 23:04:42 +1000 | [diff] [blame] | 1039 | their ``__init__`` method (for example, file objects) or in their |
Nick Coghlan | 3267a30 | 2012-05-21 22:54:43 +1000 | [diff] [blame] | 1040 | ``__enter__`` method (for example, synchronisation objects from the |
| 1041 | :mod:`threading` module). |
| 1042 | |
| 1043 | (:issue:`13585`) |
| 1044 | |
| 1045 | |
Éric Araujo | 84b8ed8 | 2011-08-29 21:42:47 +0200 | [diff] [blame] | 1046 | crypt |
| 1047 | ----- |
| 1048 | |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 1049 | Addition of salt and modular crypt format (hashing method) and the :func:`~crypt.mksalt` |
Victor Stinner | c78fb33 | 2011-09-21 03:35:44 +0200 | [diff] [blame] | 1050 | function to the :mod:`crypt` module. |
Éric Araujo | 84b8ed8 | 2011-08-29 21:42:47 +0200 | [diff] [blame] | 1051 | |
| 1052 | (:issue:`10924`) |
| 1053 | |
Victor Stinner | a7878b7 | 2011-07-14 23:07:44 +0200 | [diff] [blame] | 1054 | curses |
| 1055 | ------ |
| 1056 | |
Victor Stinner | 0fdfceb | 2011-11-25 22:10:02 +0100 | [diff] [blame] | 1057 | * If the :mod:`curses` module is linked to the ncursesw library, use Unicode |
| 1058 | functions when Unicode strings or characters are passed (e.g. |
| 1059 | :c:func:`waddwstr`), and bytes functions otherwise (e.g. :c:func:`waddstr`). |
| 1060 | * Use the locale encoding instead of ``utf-8`` to encode Unicode strings. |
| 1061 | * :class:`curses.window` has a new :attr:`curses.window.encoding` attribute. |
Victor Stinner | c78fb33 | 2011-09-21 03:35:44 +0200 | [diff] [blame] | 1062 | * The :class:`curses.window` class has a new :meth:`~curses.window.get_wch` |
| 1063 | method to get a wide character |
| 1064 | * The :mod:`curses` module has a new :meth:`~curses.unget_wch` function to |
| 1065 | push a wide character so the next :meth:`~curses.window.get_wch` will return |
| 1066 | it |
Victor Stinner | a7878b7 | 2011-07-14 23:07:44 +0200 | [diff] [blame] | 1067 | |
Victor Stinner | c78fb33 | 2011-09-21 03:35:44 +0200 | [diff] [blame] | 1068 | (Contributed by Iñigo Serna in :issue:`6755`) |
Victor Stinner | a7878b7 | 2011-07-14 23:07:44 +0200 | [diff] [blame] | 1069 | |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 1070 | datetime |
| 1071 | -------- |
| 1072 | |
| 1073 | * Equality comparisons between naive and aware :class:`~datetime.datetime` |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 1074 | instances now return :const:`False` instead of raising :exc:`TypeError` |
| 1075 | (:issue:`15006`). |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 1076 | * New :meth:`datetime.datetime.timestamp` method: Return POSIX timestamp |
| 1077 | corresponding to the :class:`~datetime.datetime` instance. |
| 1078 | * The :meth:`datetime.datetime.strftime` method supports formatting years |
| 1079 | older than 1000. |
R David Murray | defdb16 | 2012-09-29 10:53:31 -0400 | [diff] [blame] | 1080 | * The :meth:`datetime.datetime.astimezone` method can now be |
Alexander Belopolsky | 35d600c | 2012-08-22 23:14:29 -0400 | [diff] [blame] | 1081 | called without arguments to convert datetime instance to the system |
| 1082 | timezone. |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 1083 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 1084 | |
| 1085 | .. _new-decimal: |
| 1086 | |
Stefan Krah | 1919b7e | 2012-03-21 18:25:23 +0100 | [diff] [blame] | 1087 | decimal |
| 1088 | ------- |
| 1089 | |
| 1090 | :issue:`7652` - integrate fast native decimal arithmetic. |
| 1091 | C-module and libmpdec written by Stefan Krah. |
| 1092 | |
| 1093 | The new C version of the decimal module integrates the high speed libmpdec |
Stefan Krah | bf80308 | 2012-04-01 13:07:24 +0200 | [diff] [blame] | 1094 | library for arbitrary precision correctly-rounded decimal floating point |
| 1095 | arithmetic. libmpdec conforms to IBM's General Decimal Arithmetic Specification. |
Stefan Krah | 1919b7e | 2012-03-21 18:25:23 +0100 | [diff] [blame] | 1096 | |
Stefan Krah | 0c0914e | 2012-04-09 20:31:15 +0200 | [diff] [blame] | 1097 | Performance gains range from 10x for database applications to 100x for |
Stefan Krah | bf80308 | 2012-04-01 13:07:24 +0200 | [diff] [blame] | 1098 | numerically intensive applications. These numbers are expected gains |
| 1099 | for standard precisions used in decimal floating point arithmetic. Since |
| 1100 | the precision is user configurable, the exact figures may vary. For example, |
| 1101 | in integer bignum arithmetic the differences can be significantly higher. |
| 1102 | |
| 1103 | The following table is meant as an illustration. Benchmarks are available |
Georg Brandl | 204e789 | 2012-04-01 13:10:58 +0200 | [diff] [blame] | 1104 | at http://www.bytereef.org/mpdecimal/quickstart.html. |
Stefan Krah | 1919b7e | 2012-03-21 18:25:23 +0100 | [diff] [blame] | 1105 | |
| 1106 | +---------+-------------+--------------+-------------+ |
| 1107 | | | decimal.py | _decimal | speedup | |
| 1108 | +=========+=============+==============+=============+ |
Stefan Krah | a3f4a16 | 2012-09-01 14:27:51 +0200 | [diff] [blame] | 1109 | | pi | 42.02s | 0.345s | 120x | |
Stefan Krah | 1919b7e | 2012-03-21 18:25:23 +0100 | [diff] [blame] | 1110 | +---------+-------------+--------------+-------------+ |
| 1111 | | telco | 172.19s | 5.68s | 30x | |
| 1112 | +---------+-------------+--------------+-------------+ |
| 1113 | | psycopg | 3.57s | 0.29s | 12x | |
| 1114 | +---------+-------------+--------------+-------------+ |
| 1115 | |
| 1116 | Features |
| 1117 | ~~~~~~~~ |
| 1118 | |
| 1119 | * The :exc:`~decimal.FloatOperation` signal optionally enables stricter |
| 1120 | semantics for mixing floats and Decimals. |
| 1121 | |
| 1122 | * If Python is compiled without threads, the C version automatically |
| 1123 | disables the expensive thread local context machinery. In this case, |
| 1124 | the variable :data:`~decimal.HAVE_THREADS` is set to False. |
| 1125 | |
| 1126 | API changes |
| 1127 | ~~~~~~~~~~~ |
| 1128 | |
| 1129 | * The C module has the following context limits, depending on the machine |
| 1130 | architecture: |
| 1131 | |
| 1132 | +-------------------+---------------------+------------------------------+ |
| 1133 | | | 32-bit | 64-bit | |
| 1134 | +===================+=====================+==============================+ |
| 1135 | | :const:`MAX_PREC` | :const:`425000000` | :const:`999999999999999999` | |
| 1136 | +-------------------+---------------------+------------------------------+ |
| 1137 | | :const:`MAX_EMAX` | :const:`425000000` | :const:`999999999999999999` | |
| 1138 | +-------------------+---------------------+------------------------------+ |
| 1139 | | :const:`MIN_EMIN` | :const:`-425000000` | :const:`-999999999999999999` | |
| 1140 | +-------------------+---------------------+------------------------------+ |
| 1141 | |
| 1142 | * In the context templates (:class:`~decimal.DefaultContext`, |
| 1143 | :class:`~decimal.BasicContext` and :class:`~decimal.ExtendedContext`) |
| 1144 | the magnitude of :attr:`~decimal.Context.Emax` and |
| 1145 | :attr:`~decimal.Context.Emin` has changed to :const:`999999`. |
| 1146 | |
| 1147 | * The :class:`~decimal.Decimal` constructor in decimal.py does not observe |
| 1148 | the context limits and converts values with arbitrary exponents or precision |
| 1149 | exactly. Since the C version has internal limits, the following scheme is |
| 1150 | used: If possible, values are converted exactly, otherwise |
| 1151 | :exc:`~decimal.InvalidOperation` is raised and the result is NaN. In the |
| 1152 | latter case it is always possible to use :meth:`~decimal.Context.create_decimal` |
| 1153 | in order to obtain a rounded or inexact value. |
| 1154 | |
| 1155 | |
| 1156 | * The power function in decimal.py is always correctly-rounded. In the |
| 1157 | C version, it is defined in terms of the correctly-rounded |
| 1158 | :meth:`~decimal.Decimal.exp` and :meth:`~decimal.Decimal.ln` functions, |
| 1159 | but the final result is only "almost always correctly rounded". |
| 1160 | |
| 1161 | |
| 1162 | * In the C version, the context dictionary containing the signals is a |
| 1163 | :class:`~collections.abc.MutableMapping`. For speed reasons, |
| 1164 | :attr:`~decimal.Context.flags` and :attr:`~decimal.Context.traps` always |
| 1165 | refer to the same :class:`~collections.abc.MutableMapping` that the context |
| 1166 | was initialized with. If a new signal dictionary is assigned, |
| 1167 | :attr:`~decimal.Context.flags` and :attr:`~decimal.Context.traps` |
| 1168 | are updated with the new values, but they do not reference the RHS |
| 1169 | dictionary. |
| 1170 | |
| 1171 | |
| 1172 | * Pickling a :class:`~decimal.Context` produces a different output in order |
| 1173 | to have a common interchange format for the Python and C versions. |
| 1174 | |
| 1175 | |
| 1176 | * The order of arguments in the :class:`~decimal.Context` constructor has been |
| 1177 | changed to match the order displayed by :func:`repr`. |
| 1178 | |
| 1179 | |
Stefan Krah | af3f3a7 | 2012-08-30 12:33:55 +0200 | [diff] [blame] | 1180 | * The ``watchexp`` parameter in the :meth:`~decimal.Decimal.quantize` method |
| 1181 | is deprecated. |
| 1182 | |
| 1183 | |
R David Murray | f23e2b6 | 2012-09-29 19:41:26 -0400 | [diff] [blame] | 1184 | .. _new-email: |
| 1185 | |
R David Murray | 77ac351 | 2012-09-29 15:43:33 -0400 | [diff] [blame] | 1186 | email |
| 1187 | ----- |
| 1188 | |
| 1189 | Policy Framework |
| 1190 | ~~~~~~~~~~~~~~~~ |
| 1191 | |
| 1192 | The email package now has a :mod:`~email.policy` framework. A |
| 1193 | :class:`~email.policy.Policy` is an object with several methods and properties |
| 1194 | that control how the email package behaves. The primary policy for Python 3.3 |
| 1195 | is the :class:`~email.policy.Compat32` policy, which provides backward |
| 1196 | compatibility with the email package in Python 3.2. A ``policy`` can be |
| 1197 | specified when an email message is parsed by a :mod:`~email.parser`, or when a |
| 1198 | :class:`~email.message.Message` object is created, or when an email is |
| 1199 | serialized using a :mod:`~email.generator`. Unless overridden, a policy passed |
| 1200 | to a ``parser`` is inherited by all the ``Message`` object and sub-objects |
| 1201 | created by the ``parser``. By default a ``generator`` will use the policy of |
| 1202 | the ``Message`` object it is serializing. The default policy is |
| 1203 | :data:`~email.policy.compat32`. |
| 1204 | |
| 1205 | The minimum set of controls implemented by all ``policy`` objects are: |
| 1206 | |
| 1207 | =============== ======================================================= |
| 1208 | max_line_length The maximum length, excluding the linesep character(s), |
| 1209 | individual lines may have when a ``Message`` is |
| 1210 | serialized. Defaults to 78. |
| 1211 | |
| 1212 | linesep The character used to separate individual lines when a |
| 1213 | ``Message`` is serialized. Defaults to ``\n``. |
| 1214 | |
| 1215 | cte_type ``7bit`` or ``8bit``. ``8bit`` applies only to a |
| 1216 | ``Bytes`` ``generator``, and means that non-ASCII may |
| 1217 | be used where allowed by the protocol (or where it |
| 1218 | exists in the original input). |
| 1219 | |
| 1220 | raise_on_defect Causes a ``parser`` to raise error when defects are |
| 1221 | encountered instead of adding them to the ``Message`` |
| 1222 | object's ``defects`` list. |
| 1223 | =============== ======================================================= |
| 1224 | |
| 1225 | A new policy instance, with new settings, is created using the |
| 1226 | :meth:`~email.policy.Policy.clone` method of policy objects. ``clone`` takes |
| 1227 | any of the above controls as keyword arguments. Any control not specified in |
| 1228 | the call retains its default value. Thus you can create a policy that uses |
| 1229 | ``\r\n`` linesep characters like this:: |
| 1230 | |
| 1231 | mypolicy = compat32.clone(linesep='\r\n') |
| 1232 | |
| 1233 | Policies can be used to make the generation of messages in the format needed by |
| 1234 | your application simpler. Instead of having to remember to specify |
| 1235 | ``linesep='\r\n'`` in all the places you call a ``generator``, you can specify |
| 1236 | it once, when you set the policy used by the ``parser`` or the ``Message``, |
| 1237 | whichever your program uses to create ``Message`` objects. On the other hand, |
| 1238 | if you need to generate messages in multiple forms, you can still specify the |
| 1239 | parameters in the appropriate ``generator`` call. Or you can have custom |
| 1240 | policy instances for your different cases, and pass those in when you create |
| 1241 | the ``generator``. |
| 1242 | |
| 1243 | |
| 1244 | Provisional Policy with New Header API |
| 1245 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1246 | |
| 1247 | While the policy framework is worthwhile all by itself, the main motivation for |
| 1248 | introducing it is to allow the creation of new policies that implement new |
| 1249 | features for the email package in a way that maintains backward compatibility |
| 1250 | for those who do not use the new policies. Because the new policies introduce a |
| 1251 | new API, we are releasing them in Python 3.3 as a :term:`provisional policy |
| 1252 | <provisional package>`. Backwards incompatible changes (up to and including |
| 1253 | removal of the code) may occur if deemed necessary by the core developers. |
| 1254 | |
| 1255 | The new policies are instances of :class:`~email.policy.EmailPolicy`, |
| 1256 | and add the following additional controls: |
| 1257 | |
| 1258 | =============== ======================================================= |
| 1259 | refold_source Controls whether or not headers parsed by a |
| 1260 | :mod:`~email.parser` are refolded by the |
| 1261 | :mod:`~email.generator`. It can be ``none``, ``long``, |
| 1262 | or ``all``. The default is ``long``, which means that |
| 1263 | source headers with a line longer than |
| 1264 | ``max_line_length`` get refolded. ``none`` means no |
| 1265 | line get refolded, and ``all`` means that all lines |
| 1266 | get refolded. |
| 1267 | |
| 1268 | header_factory A callable that take a ``name`` and ``value`` and |
| 1269 | produces a custom header object. |
| 1270 | =============== ======================================================= |
| 1271 | |
| 1272 | The ``header_factory`` is the key to the new features provided by the new |
| 1273 | policies. When one of the new policies is used, any header retrieved from |
| 1274 | a ``Message`` object is an object produced by the ``header_factory``, and any |
| 1275 | time you set a header on a ``Message`` it becomes an object produced by |
| 1276 | ``header_factory``. All such header objects have a ``name`` attribute equal |
| 1277 | to the header name. Address and Date headers have additional attributes |
| 1278 | that give you access to the parsed data of the header. This means you can now |
| 1279 | do things like this:: |
| 1280 | |
| 1281 | >>> m = Message(policy=SMTP) |
| 1282 | >>> m['To'] = 'Éric <foo@example.com>' |
| 1283 | >>> m['to'] |
| 1284 | 'Éric <foo@example.com>' |
| 1285 | >>> m['to'].addresses |
| 1286 | (Address(display_name='Éric', username='foo', domain='example.com'),) |
| 1287 | >>> m['to'].addresses[0].username |
| 1288 | 'foo' |
| 1289 | >>> m['to'].addresses[0].display_name |
| 1290 | 'Éric' |
| 1291 | >>> m['Date'] = email.utils.localtime() |
| 1292 | >>> m['Date'].datetime |
| 1293 | datetime.datetime(2012, 5, 25, 21, 39, 24, 465484, tzinfo=datetime.timezone(datetime.timedelta(-1, 72000), 'EDT')) |
| 1294 | >>> m['Date'] |
| 1295 | 'Fri, 25 May 2012 21:44:27 -0400' |
| 1296 | >>> print(m) |
| 1297 | To: =?utf-8?q?=C3=89ric?= <foo@example.com> |
| 1298 | Date: Fri, 25 May 2012 21:44:27 -0400 |
| 1299 | |
| 1300 | You will note that the unicode display name is automatically encoded as |
| 1301 | ``utf-8`` when the message is serialized, but that when the header is accessed |
| 1302 | directly, you get the unicode version. This eliminates any need to deal with |
| 1303 | the :mod:`email.header` :meth:`~email.header.decode_header` or |
| 1304 | :meth:`~email.header.make_header` functions. |
| 1305 | |
| 1306 | You can also create addresses from parts:: |
| 1307 | |
| 1308 | >>> m['cc'] = [Group('pals', [Address('Bob', 'bob', 'example.com'), |
| 1309 | ... Address('Sally', 'sally', 'example.com')]), |
| 1310 | ... Address('Bonzo', addr_spec='bonz@laugh.com')] |
| 1311 | >>> print(m) |
| 1312 | To: =?utf-8?q?=C3=89ric?= <foo@example.com> |
| 1313 | Date: Fri, 25 May 2012 21:44:27 -0400 |
| 1314 | cc: pals: Bob <bob@example.com>, Sally <sally@example.com>;, Bonzo <bonz@laugh.com> |
| 1315 | |
| 1316 | Decoding to unicode is done automatically:: |
| 1317 | |
| 1318 | >>> m2 = message_from_string(str(m)) |
| 1319 | >>> m2['to'] |
| 1320 | 'Éric <foo@example.com>' |
| 1321 | |
| 1322 | When you parse a message, you can use the ``addresses`` and ``groups`` |
| 1323 | attributes of the header objects to access the groups and individual |
| 1324 | addresses:: |
| 1325 | |
| 1326 | >>> m2['cc'].addresses |
| 1327 | (Address(display_name='Bob', username='bob', domain='example.com'), Address(display_name='Sally', username='sally', domain='example.com'), Address(display_name='Bonzo', username='bonz', domain='laugh.com')) |
| 1328 | >>> m2['cc'].groups |
| 1329 | (Group(display_name='pals', addresses=(Address(display_name='Bob', username='bob', domain='example.com'), Address(display_name='Sally', username='sally', domain='example.com')), Group(display_name=None, addresses=(Address(display_name='Bonzo', username='bonz', domain='laugh.com'),)) |
| 1330 | |
| 1331 | In summary, if you use one of the new policies, header manipulation works the |
| 1332 | way it ought to: your application works with unicode strings, and the email |
| 1333 | package transparently encodes and decodes the unicode to and from the RFC |
| 1334 | standard Content Transfer Encodings. |
| 1335 | |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1336 | Other API Changes |
| 1337 | ~~~~~~~~~~~~~~~~~ |
| 1338 | |
R David Murray | 3430fb8 | 2012-10-02 18:24:56 -0400 | [diff] [blame] | 1339 | New :class:`~email.parser.BytesHeaderParser`, added to the :mod:`~email.parser` |
| 1340 | module to complement :class:`~email.parser.HeaderParser` and complete the Bytes |
| 1341 | API. |
| 1342 | |
| 1343 | New utility functions: |
| 1344 | |
| 1345 | * :func:`~email.utils.format_datetime`: given a :class:`~datetime.datetime`, |
| 1346 | produce a string formatted for use in an email header. |
| 1347 | |
| 1348 | * :func:`~email.utils.parsedate_to_datetime`: given a date string from |
| 1349 | an email header, convert it into an aware :class:`~datetime.datetime`, |
| 1350 | or a naive :class:`~datetime.datetime` if the offset is ``-0000``. |
| 1351 | |
| 1352 | * :func:`~email.utils.localtime`: With no argument, returns the |
| 1353 | current local time as an aware :class:`~datetime.datetime` using the local |
| 1354 | :class:`~datetime.timezone`. Given an aware :class:`~datetime.datetime`, |
| 1355 | converts it into an aware :class:`~datetime.datetime` using the |
| 1356 | local :class:`~datetime.timezone`. |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1357 | |
R David Murray | 77ac351 | 2012-09-29 15:43:33 -0400 | [diff] [blame] | 1358 | |
Victor Stinner | 811db3b | 2011-09-21 03:20:03 +0200 | [diff] [blame] | 1359 | ftplib |
| 1360 | ------ |
| 1361 | |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 1362 | * :class:`ftplib.FTP` now accepts a ``source_address`` keyword argument to |
| 1363 | specify the ``(host, port)`` to use as the source address in the bind call |
| 1364 | when creating the outgoing socket. (Contributed by Giampaolo Rodolà |
| 1365 | in :issue:`8594`.) |
| 1366 | |
Giampaolo Rodola' | 49379c0 | 2012-09-25 12:32:46 -0700 | [diff] [blame] | 1367 | * The :class:`~ftplib.FTP_TLS` class now provides a new |
| 1368 | :func:`~ftplib.FTP_TLS.ccc` function to revert control channel back to |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 1369 | plaintext. This can be useful to take advantage of firewalls that know how |
| 1370 | to handle NAT with non-secure FTP without opening fixed ports. (Contributed |
| 1371 | by Giampaolo Rodolà in :issue:`12139`) |
Victor Stinner | 811db3b | 2011-09-21 03:20:03 +0200 | [diff] [blame] | 1372 | |
Giampaolo Rodola' | 49379c0 | 2012-09-25 12:32:46 -0700 | [diff] [blame] | 1373 | * Added :meth:`ftplib.FTP.mlsd` method which provides a parsable directory |
| 1374 | listing format and deprecates :meth:`ftplib.FTP.nlst` and |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 1375 | :meth:`ftplib.FTP.dir`. (Contributed by Giampaolo Rodolà in :issue:`11072`) |
Victor Stinner | 811db3b | 2011-09-21 03:20:03 +0200 | [diff] [blame] | 1376 | |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 1377 | |
| 1378 | functools |
| 1379 | --------- |
| 1380 | |
| 1381 | The :func:`functools.lru_cache` decorator now accepts a ``typed`` keyword |
| 1382 | argument (that defaults to ``False`` to ensure that it caches values of |
| 1383 | different types that compare equal in separate cache slots. (Contributed |
| 1384 | by Raymond Hettinger in :issue:`13227`.) |
| 1385 | |
| 1386 | |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 1387 | gc |
| 1388 | -- |
| 1389 | |
| 1390 | It is now possible to register callbacks invoked by the garbage collector |
Georg Brandl | a81b481 | 2012-08-11 08:43:59 +0200 | [diff] [blame] | 1391 | before and after collection using the new :data:`~gc.callbacks` list. |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 1392 | |
| 1393 | |
Christian Heimes | 3194037 | 2012-06-26 10:16:55 +0200 | [diff] [blame] | 1394 | hmac |
| 1395 | ---- |
| 1396 | |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 1397 | A new :func:`~hmac.compare_digest` function has been added to prevent side |
| 1398 | channel attacks on digests through timing analysis. (Contributed by Nick |
| 1399 | Coghlan and Christian Heimes in :issue:`15061`) |
Ezio Melotti | 461f41d | 2012-09-26 17:43:23 +0300 | [diff] [blame] | 1400 | |
| 1401 | |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1402 | http |
| 1403 | ---- |
| 1404 | |
| 1405 | :class:`http.server.BaseHTTPRequestHandler` now buffers the headers and writes |
| 1406 | them all at once when :meth:`~http.server.BaseHTTPRequestHandler.end_headers` is |
| 1407 | called. A new method :meth:`~http.server.BaseHTTPRequestHandler.flush_headers` |
| 1408 | can be used to directly manage when the accumlated headers are sent. |
| 1409 | (Contributed by Andrew Schaaf in :issue:`3709`.) |
| 1410 | |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 1411 | :class:`http.server` now produces valid ``HTML 4.01 strict`` output. |
| 1412 | (Contributed by Ezio Melotti in :issue:`13295`.) |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1413 | |
R David Murray | fd74096 | 2012-10-06 22:08:08 -0400 | [diff] [blame] | 1414 | :class:`http.client.HTTPResponse` now has a |
| 1415 | :meth:`~http.client.HTTPResponse.readinto` method, which means it can be used |
| 1416 | as a :class:`io.RawIOBase` class. (Contributed by John Kuhn in |
| 1417 | :issue:`13464`.) |
| 1418 | |
Ezio Melotti | 461f41d | 2012-09-26 17:43:23 +0300 | [diff] [blame] | 1419 | |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 1420 | html |
| 1421 | ---- |
| 1422 | |
| 1423 | :class:`html.parser.HTMLParser` is now able to parse broken markup without |
Ezio Melotti | 461f41d | 2012-09-26 17:43:23 +0300 | [diff] [blame] | 1424 | raising errors, therefore the *strict* argument of the constructor and the |
| 1425 | :exc:`~html.parser.HTMLParseError` exception are now deprecated. |
| 1426 | The ability to parse broken markup is the result of a number of bug fixes that |
| 1427 | are also available on the latest bug fix releases of Python 2.7/3.2. |
Ezio Melotti | 461f41d | 2012-09-26 17:43:23 +0300 | [diff] [blame] | 1428 | (Contributed by Ezio Melotti in :issue:`15114`, and :issue:`14538`, |
| 1429 | :issue:`13993`, :issue:`13960`, :issue:`13358`, :issue:`1745761`, |
| 1430 | :issue:`755670`, :issue:`13357`, :issue:`12629`, :issue:`1200313`, |
| 1431 | :issue:`670664`, :issue:`13273`, :issue:`12888`, :issue:`7311`) |
| 1432 | |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 1433 | A new :data:`~html.entities.html5` dictionary that maps HTML5 named character |
| 1434 | references to the equivalent Unicode character(s) (e.g. ``html5['gt;'] == |
| 1435 | '>'``) has been added to the :mod:`html.entities` module. The dictionary is |
| 1436 | now also used by :class:`~html.parser.HTMLParser`. (Contributed by Ezio |
| 1437 | Melotti in :issue:`11113` and :issue:`15156`) |
| 1438 | |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1439 | |
Antoine Pitrou | 5a8bc6f | 2011-11-17 02:20:48 +0100 | [diff] [blame] | 1440 | imaplib |
| 1441 | ------- |
| 1442 | |
| 1443 | The :class:`~imaplib.IMAP4_SSL` constructor now accepts an SSLContext |
| 1444 | parameter to control parameters of the secure channel. |
| 1445 | |
| 1446 | (Contributed by Sijin Joseph in :issue:`8808`) |
| 1447 | |
| 1448 | |
Nick Coghlan | 2f92e54 | 2012-06-23 19:39:55 +1000 | [diff] [blame] | 1449 | inspect |
| 1450 | ------- |
| 1451 | |
| 1452 | A new :func:`~inspect.getclosurevars` function has been added. This function |
| 1453 | reports the current binding of all names referenced from the function body and |
| 1454 | where those names were resolved, making it easier to verify correct internal |
| 1455 | state when testing code that relies on stateful closures. |
| 1456 | |
| 1457 | (Contributed by Meador Inge and Nick Coghlan in :issue:`13062`) |
| 1458 | |
Nick Coghlan | 04e2e3f | 2012-06-23 19:52:05 +1000 | [diff] [blame] | 1459 | A new :func:`~inspect.getgeneratorlocals` function has been added. This |
| 1460 | function reports the current binding of local variables in the generator's |
| 1461 | stack frame, making it easier to verify correct internal state when testing |
| 1462 | generators. |
| 1463 | |
| 1464 | (Contributed by Meador Inge in :issue:`15153`) |
| 1465 | |
Charles-François Natali | dc3044c | 2012-01-09 22:40:02 +0100 | [diff] [blame] | 1466 | io |
| 1467 | -- |
| 1468 | |
Charles-François Natali | d612de1 | 2012-01-14 11:51:00 +0100 | [diff] [blame] | 1469 | The :func:`~io.open` function has a new ``'x'`` mode that can be used to |
| 1470 | exclusively create a new file, and raise a :exc:`FileExistsError` if the file |
| 1471 | already exists. It is based on the C11 'x' mode to fopen(). |
Charles-François Natali | dc3044c | 2012-01-09 22:40:02 +0100 | [diff] [blame] | 1472 | |
| 1473 | (Contributed by David Townshend in :issue:`12760`) |
| 1474 | |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 1475 | The constructor of the :class:`~io.TextIOWrapper` class has a new |
| 1476 | *write_through* optional argument. If *write_through* is ``True``, calls to |
| 1477 | :meth:`~io.TextIOWrapper.write` are guaranteed not to be buffered: any data |
| 1478 | written on the :class:`~io.TextIOWrapper` object is immediately handled to its |
| 1479 | underlying binary buffer. |
| 1480 | |
Charles-François Natali | dc3044c | 2012-01-09 22:40:02 +0100 | [diff] [blame] | 1481 | |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1482 | itertools |
| 1483 | --------- |
| 1484 | |
| 1485 | :func:`~itertools.accumulate` now takes an optional ``func`` argument for |
| 1486 | providing a user-supplied binary function. |
| 1487 | |
| 1488 | |
| 1489 | logging |
| 1490 | ------- |
| 1491 | |
R David Murray | 3430fb8 | 2012-10-02 18:24:56 -0400 | [diff] [blame] | 1492 | The :func:`~logging.basicConfig` function now supports an optional ``handlers`` |
| 1493 | argument taking an iterable of handlers to be added to the root logger. |
| 1494 | |
| 1495 | A class level attribute :attr:`~logging.handlers.SysLogHandler.append_nul` has |
| 1496 | been added to :class:`~logging.handlers.SysLogHandler` to allow control of the |
| 1497 | appending of the ``NUL`` (``\000``) byte to syslog records, since for some |
| 1498 | deamons it is required while for others it is passed through to the log. |
| 1499 | |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1500 | |
| 1501 | |
Victor Stinner | fa0e3d5 | 2011-05-09 01:01:09 +0200 | [diff] [blame] | 1502 | math |
| 1503 | ---- |
| 1504 | |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 1505 | The :mod:`math` module has a new function, :func:`~math.log2`, which returns |
| 1506 | the base-2 logarithm of *x*. |
Victor Stinner | fa0e3d5 | 2011-05-09 01:01:09 +0200 | [diff] [blame] | 1507 | |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 1508 | (Written by Mark Dickinson in :issue:`11888`). |
Victor Stinner | fa0e3d5 | 2011-05-09 01:01:09 +0200 | [diff] [blame] | 1509 | |
| 1510 | |
R David Murray | 3430fb8 | 2012-10-02 18:24:56 -0400 | [diff] [blame] | 1511 | mmap |
| 1512 | ---- |
| 1513 | |
| 1514 | The :meth:`~mmap.mmap.read` method is now more compatible with other file-like |
| 1515 | objects: if the argument is omitted or specified as ``None``, it returns the |
| 1516 | bytes from the current file position to the end of the mapping. (Contributed |
| 1517 | by Petri Lehtinen in :issue:`12021`.) |
| 1518 | |
| 1519 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 1520 | multiprocessing |
| 1521 | --------------- |
| 1522 | |
| 1523 | The new :func:`multiprocessing.connection.wait` function allows to poll |
| 1524 | multiple objects (such as connections, sockets and pipes) with a timeout. |
| 1525 | (Contributed by Richard Oudkerk in :issue:`12328`.) |
| 1526 | |
| 1527 | :class:`multiprocessing.Connection` objects can now be transferred over |
| 1528 | multiprocessing connections. |
| 1529 | (Contributed by Richard Oudkerk in :issue:`4892`.) |
| 1530 | |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 1531 | :class:`multiprocessing.Process` now accepts a ``daemon`` keyword argument |
| 1532 | to override the default behavior of inheriting the ``daemon`` flag from |
| 1533 | the parent process (:issue:`6064`). |
| 1534 | |
R David Murray | 994ce1a | 2012-10-02 10:19:08 -0400 | [diff] [blame] | 1535 | New attribute attribute :data:`multiprocessing.Process.sentinel` allows a |
| 1536 | program to wait on multiple :class:`~multiprocessing.Process` objects at one |
| 1537 | time using the appropriate OS primitives (for example, :mod:`select` on |
| 1538 | posix systems). |
| 1539 | |
R David Murray | ace5162 | 2012-10-06 22:26:52 -0400 | [diff] [blame^] | 1540 | New methods :meth:`multiprocessing.pool.Pool.starmap` and |
| 1541 | :meth:`~multiprocessing.pool.Pool.starmap_async` provide |
| 1542 | :func:`itertools.starmap` equivalents to the existing |
| 1543 | :meth:`multiprocessing.pool.Pool.map` and |
| 1544 | :meth:`~multiprocessing.pool.Pool.map_async` functions. (Contributed by Hynek |
| 1545 | Schlawack in :issue:`12708`.) |
| 1546 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 1547 | |
Victor Stinner | fa0e3d5 | 2011-05-09 01:01:09 +0200 | [diff] [blame] | 1548 | nntplib |
| 1549 | ------- |
| 1550 | |
| 1551 | The :class:`nntplib.NNTP` class now supports the context manager protocol to |
| 1552 | unconditionally consume :exc:`socket.error` exceptions and to close the NNTP |
| 1553 | connection when done:: |
| 1554 | |
| 1555 | >>> from nntplib import NNTP |
Ezio Melotti | 3c14b4e | 2011-07-13 11:44:44 +0300 | [diff] [blame] | 1556 | >>> with NNTP('news.gmane.org') as n: |
Victor Stinner | fa0e3d5 | 2011-05-09 01:01:09 +0200 | [diff] [blame] | 1557 | ... n.group('gmane.comp.python.committers') |
| 1558 | ... |
Ezio Melotti | 04f648c | 2011-07-26 09:37:46 +0300 | [diff] [blame] | 1559 | ('211 1755 1 1755 gmane.comp.python.committers', 1755, 1, 1755, 'gmane.comp.python.committers') |
Victor Stinner | fa0e3d5 | 2011-05-09 01:01:09 +0200 | [diff] [blame] | 1560 | >>> |
| 1561 | |
| 1562 | (Contributed by Giampaolo Rodolà in :issue:`9795`) |
| 1563 | |
| 1564 | |
Giampaolo Rodolà | c9c2c8b | 2011-02-25 14:39:16 +0000 | [diff] [blame] | 1565 | os |
| 1566 | -- |
| 1567 | |
Charles-François Natali | a003af1 | 2011-06-01 20:30:52 +0200 | [diff] [blame] | 1568 | * The :mod:`os` module has a new :func:`~os.pipe2` function that makes it |
| 1569 | possible to create a pipe with :data:`~os.O_CLOEXEC` or |
| 1570 | :data:`~os.O_NONBLOCK` flags set atomically. This is especially useful to |
| 1571 | avoid race conditions in multi-threaded programs. |
| 1572 | |
Giampaolo Rodolà | 18e8bcb | 2011-02-25 20:57:54 +0000 | [diff] [blame] | 1573 | * The :mod:`os` module has a new :func:`~os.sendfile` function which provides |
| 1574 | an efficent "zero-copy" way for copying data from one file (or socket) |
| 1575 | descriptor to another. The phrase "zero-copy" refers to the fact that all of |
| 1576 | the copying of data between the two descriptors is done entirely by the |
| 1577 | kernel, with no copying of data into userspace buffers. :func:`~os.sendfile` |
| 1578 | can be used to efficiently copy data from a file on disk to a network socket, |
| 1579 | e.g. for downloading a file. |
Giampaolo Rodolà | c9c2c8b | 2011-02-25 14:39:16 +0000 | [diff] [blame] | 1580 | |
Giampaolo Rodolà | 18e8bcb | 2011-02-25 20:57:54 +0000 | [diff] [blame] | 1581 | (Patch submitted by Ross Lagerwall and Giampaolo Rodolà in :issue:`10882`.) |
| 1582 | |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 1583 | * To avoid race conditions like symlink attacks and issues with temporary |
| 1584 | files and directories, it is more reliable (and also faster) to manipulate |
| 1585 | file descriptors instead of file names. Python 3.3 enhances existing functions |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 1586 | and introduces new functions to work on file descriptors (:issue:`4761`, |
Larry Hastings | 9471797 | 2012-09-21 09:30:19 -0700 | [diff] [blame] | 1587 | :issue:`10755` and :issue:`14626`). |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 1588 | |
| 1589 | - The :mod:`os` module has a new :func:`~os.fwalk` function similar to |
| 1590 | :func:`~os.walk` except that it also yields file descriptors referring to the |
| 1591 | directories visited. This is especially useful to avoid symlink races. |
| 1592 | |
| 1593 | - The following functions get new optional *dir_fd* (:ref:`paths relative to |
| 1594 | directory descriptors <dir_fd>`) and/or *follow_symlinks* (:ref:`not |
| 1595 | following symlinks <follow_symlinks>`): |
| 1596 | :func:`~os.access`, :func:`~os.chflags`, :func:`~os.chmod`, :func:`~os.chown`, |
| 1597 | :func:`~os.link`, :func:`~os.lstat`, :func:`~os.mkdir`, :func:`~os.mkfifo`, |
| 1598 | :func:`~os.mknod`, :func:`~os.open`, :func:`~os.readlink`, :func:`~os.remove`, |
| 1599 | :func:`~os.rename`, :func:`~os.replace`, :func:`~os.rmdir`, :func:`~os.stat`, |
R David Murray | c652ce6 | 2012-09-30 20:07:42 -0400 | [diff] [blame] | 1600 | :func:`~os.symlink`, :func:`~os.unlink`, :func:`~os.utime`. Platform |
| 1601 | support for using these parameters can be checked via the sets |
| 1602 | :data:`os.supports_dir_fd` and :data:`os.supports_follows_symlinks`. |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 1603 | |
| 1604 | - The following functions now support a file descriptor for their path argument: |
| 1605 | :func:`~os.chdir`, :func:`~os.chmod`, :func:`~os.chown`, |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 1606 | :func:`~os.execve`, :func:`~os.listdir`, :func:`~os.pathconf`, :func:`~os.path.exists`, |
R David Murray | c652ce6 | 2012-09-30 20:07:42 -0400 | [diff] [blame] | 1607 | :func:`~os.stat`, :func:`~os.statvfs`, :func:`~os.utime`. Platform support |
| 1608 | for this can be checked via the :data:`os.supports_fd` set. |
| 1609 | |
| 1610 | * :func:`~os.access` accepts an ``effective_ids`` keyword argument to turn on |
| 1611 | using the effective uid/gid rather than the real uid/gid in the access check. |
| 1612 | Platform support for this can be checked via the |
| 1613 | :data:`~os.supports_effective_ids` set. |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 1614 | |
Giampaolo Rodolà | 18e8bcb | 2011-02-25 20:57:54 +0000 | [diff] [blame] | 1615 | * The :mod:`os` module has two new functions: :func:`~os.getpriority` and |
| 1616 | :func:`~os.setpriority`. They can be used to get or set process |
| 1617 | niceness/priority in a fashion similar to :func:`os.nice` but extended to all |
| 1618 | processes instead of just the current one. |
| 1619 | |
| 1620 | (Patch submitted by Giampaolo Rodolà in :issue:`10784`.) |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 1621 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 1622 | * The new :func:`os.replace` function allows cross-platform renaming of a |
| 1623 | file with overwriting the destination. With :func:`os.rename`, an existing |
| 1624 | destination file is overwritten under POSIX, but raises an error under |
| 1625 | Windows. |
| 1626 | (Contributed by Antoine Pitrou in :issue:`8828`.) |
| 1627 | |
Larry Hastings | 9471797 | 2012-09-21 09:30:19 -0700 | [diff] [blame] | 1628 | * The stat family of functions (:func:`~os.stat`, :func:`~os.fstat`, |
| 1629 | and :func:`~os.lstat`) now support reading a file's timestamps |
| 1630 | with nanosecond precision. Symmetrically, :func:`~os.utime` |
| 1631 | can now write file timestamps with nanosecond precision. (Contributed by |
| 1632 | Larry Hastings in :issue:`14127`.) |
| 1633 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 1634 | * The new :func:`os.get_terminal_size` function queries the size of the |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 1635 | terminal attached to a file descriptor. See also |
| 1636 | :func:`shutil.get_terminal_size`. |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 1637 | (Contributed by Zbigniew Jędrzejewski-Szmek in :issue:`13609`.) |
| 1638 | |
Georg Brandl | dba3b5c | 2012-06-26 09:36:14 +0200 | [diff] [blame] | 1639 | .. XXX sort out this mess after beta1 |
Victor Stinner | e506437 | 2011-10-14 00:08:29 +0200 | [diff] [blame] | 1640 | |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 1641 | * New functions to support Linux extended attributes (:issue:`12720`): |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 1642 | :func:`~os.getxattr`, :func:`~os.listxattr`, :func:`~os.removexattr`, |
| 1643 | :func:`~os.setxattr`. |
Victor Stinner | e506437 | 2011-10-14 00:08:29 +0200 | [diff] [blame] | 1644 | |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 1645 | * New interface to the scheduler. These functions |
| 1646 | control how a process is allocated CPU time by the operating system. New |
| 1647 | functions: |
| 1648 | :func:`~os.sched_get_priority_max`, :func:`~os.sched_get_priority_min`, |
| 1649 | :func:`~os.sched_getaffinity`, :func:`~os.sched_getparam`, |
| 1650 | :func:`~os.sched_getscheduler`, :func:`~os.sched_rr_get_interval`, |
| 1651 | :func:`~os.sched_setaffinity`, :func:`~os.sched_setparam`, |
| 1652 | :func:`~os.sched_setscheduler`, :func:`~os.sched_yield`, |
Victor Stinner | e506437 | 2011-10-14 00:08:29 +0200 | [diff] [blame] | 1653 | |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 1654 | * New functions to control the file system: |
Victor Stinner | e506437 | 2011-10-14 00:08:29 +0200 | [diff] [blame] | 1655 | |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 1656 | * :func:`~os.posix_fadvise`: Announces an intention to access data in a |
| 1657 | specific pattern thus allowing the kernel to make optimizations. |
| 1658 | * :func:`~os.posix_fallocate`: Ensures that enough disk space is allocated |
| 1659 | for a file. |
| 1660 | * :func:`~os.sync`: Force write of everything to disk. |
Victor Stinner | e506437 | 2011-10-14 00:08:29 +0200 | [diff] [blame] | 1661 | |
R David Murray | c652ce6 | 2012-09-30 20:07:42 -0400 | [diff] [blame] | 1662 | * Additional new posix functions: |
Victor Stinner | e506437 | 2011-10-14 00:08:29 +0200 | [diff] [blame] | 1663 | |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 1664 | * :func:`~os.lockf`: Apply, test or remove a POSIX lock on an open file descriptor. |
| 1665 | * :func:`~os.pread`: Read from a file descriptor at an offset, the file |
| 1666 | offset remains unchanged. |
| 1667 | * :func:`~os.pwrite`: Write to a file descriptor from an offset, leaving |
| 1668 | the file offset unchanged. |
| 1669 | * :func:`~os.readv`: Read from a file descriptor into a number of writable buffers. |
| 1670 | * :func:`~os.truncate`: Truncate the file corresponding to *path*, so that |
| 1671 | it is at most *length* bytes in size. |
| 1672 | * :func:`~os.waitid`: Wait for the completion of one or more child processes. |
| 1673 | * :func:`~os.writev`: Write the contents of *buffers* to a file descriptor, |
| 1674 | where *buffers* is an arbitrary sequence of buffers. |
| 1675 | * :func:`~os.getgrouplist` (:issue:`9344`): Return list of group ids that |
| 1676 | specified user belongs to. |
Victor Stinner | e506437 | 2011-10-14 00:08:29 +0200 | [diff] [blame] | 1677 | |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 1678 | * :func:`~os.times` and :func:`~os.uname`: Return type changed from a tuple to |
| 1679 | a tuple-like object with named attributes. |
Victor Stinner | e506437 | 2011-10-14 00:08:29 +0200 | [diff] [blame] | 1680 | |
R David Murray | c652ce6 | 2012-09-30 20:07:42 -0400 | [diff] [blame] | 1681 | * Some platforms now support additional constants for the :func:`~os.lseek` |
| 1682 | function, such as ``os.SEEK_HOLE`` and ``os.SEEK_DATA``. |
| 1683 | |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 1684 | * New constants :data:`~os.RTLD_LAZY`, :data:`~os.RTLD_NOW`, |
| 1685 | :data:`~os.RTLD_GLOBAL`, :data:`~os.RTLD_LOCAL`, :data:`~os.RTLD_NODELETE`, |
| 1686 | :data:`~os.RTLD_NOLOAD`, and :data:`~os.RTLD_DEEPBIND` are available on |
| 1687 | platforms that support them. These are for use with the |
| 1688 | :func:`sys.setdlopenflags` function, and supersede the similar constants |
| 1689 | defined in :mod:`ctypes` and :mod:`DLFCN`. (Contributed by Victor Stinner |
| 1690 | in :issue:`13226`.) |
| 1691 | |
R David Murray | c652ce6 | 2012-09-30 20:07:42 -0400 | [diff] [blame] | 1692 | * :func:`os.symlink` now accepts (and ignores) the ``target_is_directory`` |
| 1693 | keyword argument on non-Windows platforms, to ease cross-platform support. |
| 1694 | |
Giampaolo Rodolà | 424298a | 2011-03-03 18:34:06 +0000 | [diff] [blame] | 1695 | |
Georg Brandl | 4c7c3c5 | 2012-03-10 22:36:48 +0100 | [diff] [blame] | 1696 | pdb |
| 1697 | --- |
| 1698 | |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 1699 | Tab-completion is now available not only for command names, but also their |
| 1700 | arguments. For example, for the ``break`` command, function and file names |
| 1701 | are completed. |
| 1702 | |
| 1703 | (Contributed by Georg Brandl in :issue:`14210`) |
Georg Brandl | 4c7c3c5 | 2012-03-10 22:36:48 +0100 | [diff] [blame] | 1704 | |
| 1705 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 1706 | pickle |
| 1707 | ------ |
| 1708 | |
| 1709 | :class:`pickle.Pickler` objects now have an optional |
| 1710 | :attr:`~pickle.Pickler.dispatch_table` attribute allowing to set per-pickler |
| 1711 | reduction functions. |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 1712 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 1713 | (Contributed by Richard Oudkerk in :issue:`14166`.) |
| 1714 | |
| 1715 | |
Victor Stinner | 383c3fc | 2011-05-25 01:35:05 +0200 | [diff] [blame] | 1716 | pydoc |
| 1717 | ----- |
| 1718 | |
Victor Stinner | 6daa33c | 2011-05-25 01:41:22 +0200 | [diff] [blame] | 1719 | The Tk GUI and the :func:`~pydoc.serve` function have been removed from the |
| 1720 | :mod:`pydoc` module: ``pydoc -g`` and :func:`~pydoc.serve` have been deprecated |
| 1721 | in Python 3.2. |
Victor Stinner | 383c3fc | 2011-05-25 01:35:05 +0200 | [diff] [blame] | 1722 | |
| 1723 | |
Antoine Pitrou | ad09b5d | 2012-06-24 22:41:33 +0200 | [diff] [blame] | 1724 | re |
| 1725 | -- |
| 1726 | |
| 1727 | :class:`str` regular expressions now support ``\u`` and ``\U`` escapes. |
| 1728 | |
| 1729 | (Contributed by Serhiy Storchaka in :issue:`3665`.) |
| 1730 | |
| 1731 | |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 1732 | sched |
| 1733 | ----- |
Victor Stinner | 754851f | 2011-04-19 23:58:51 +0200 | [diff] [blame] | 1734 | |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 1735 | * :meth:`~sched.scheduler.run` now accepts a *blocking* parameter which when |
| 1736 | set to False makes the method execute the scheduled events due to expire |
| 1737 | soonest (if any) and then return immediately. |
| 1738 | This is useful in case you want to use the :class:`~sched.scheduler` in |
| 1739 | non-blocking applications. (Contributed by Giampaolo Rodolà in :issue:`13449`) |
Victor Stinner | 754851f | 2011-04-19 23:58:51 +0200 | [diff] [blame] | 1740 | |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 1741 | * :class:`~sched.scheduler` class can now be safely used in multi-threaded |
| 1742 | environments. (Contributed by Josiah Carlson and Giampaolo Rodolà in |
| 1743 | :issue:`8684`) |
| 1744 | |
| 1745 | * *timefunc* and *delayfunct* parameters of :class:`~sched.scheduler` class |
| 1746 | constructor are now optional and defaults to :func:`time.time` and |
| 1747 | :func:`time.sleep` respectively. (Contributed by Chris Clark in |
| 1748 | :issue:`13245`) |
| 1749 | |
| 1750 | * :meth:`~sched.scheduler.enter` and :meth:`~sched.scheduler.enterabs` |
| 1751 | *argument* parameter is now optional. (Contributed by Chris Clark in |
| 1752 | :issue:`13245`) |
| 1753 | |
| 1754 | * :meth:`~sched.scheduler.enter` and :meth:`~sched.scheduler.enterabs` |
| 1755 | now accept a *kwargs* parameter. (Contributed by Chris Clark in |
| 1756 | :issue:`13245`) |
| 1757 | |
| 1758 | |
Jesus Cea | aa26488 | 2012-10-04 02:51:22 +0200 | [diff] [blame] | 1759 | select |
| 1760 | ------ |
| 1761 | |
Jesus Cea | b6bb3ad | 2012-10-04 02:58:48 +0200 | [diff] [blame] | 1762 | Solaris and derivatives platforms have a new class :class:`select.devpoll` |
| 1763 | for high performance asynchronous sockets via :file:`/dev/poll`. |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 1764 | (Contributed by Jesús Cea Avión in :issue:`6397`.) |
Jesus Cea | aa26488 | 2012-10-04 02:51:22 +0200 | [diff] [blame] | 1765 | |
| 1766 | |
R David Murray | aae2583 | 2012-09-29 09:49:05 -0400 | [diff] [blame] | 1767 | shlex |
| 1768 | ----- |
| 1769 | |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 1770 | The previously undocumented helper function ``quote`` from the |
| 1771 | :mod:`pipes` modules has been moved to the :mod:`shlex` module and |
| 1772 | documented. :func:`~shlex.quote` properly escapes all characters in a string |
| 1773 | that might be otherwise given special meaning by the shell. |
R David Murray | aae2583 | 2012-09-29 09:49:05 -0400 | [diff] [blame] | 1774 | |
| 1775 | |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 1776 | shutil |
| 1777 | ------ |
| 1778 | |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 1779 | * New functions: |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 1780 | |
| 1781 | * :func:`~shutil.disk_usage`: provides total, used and free disk space |
| 1782 | statistics. (Contributed by Giampaolo Rodolà in :issue:`12442`) |
| 1783 | * :func:`~shutil.chown`: allows one to change user and/or group of the given |
| 1784 | path also specifying the user/group names and not only their numeric |
| 1785 | ids. (Contributed by Sandro Tosi in :issue:`12191`) |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 1786 | * :func:`shutil.get_terminal_size`: returns the size of the terminal window |
| 1787 | to which the interpreter is attached. (Contributed by Zbigniew |
| 1788 | Jędrzejewski-Szmek in :issue:`13609`.) |
Victor Stinner | a929335 | 2011-04-30 15:21:58 +0200 | [diff] [blame] | 1789 | |
Larry Hastings | 9471797 | 2012-09-21 09:30:19 -0700 | [diff] [blame] | 1790 | * :func:`~shutil.copy2` and :func:`~shutil.copystat` now preserve file |
| 1791 | timestamps with nanosecond precision on platforms that support it. |
| 1792 | They also preserve file "extended attributes" on Linux. (Contributed |
| 1793 | by Larry Hastings in :issue:`14127` and :issue:`15238`.) |
| 1794 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 1795 | * Several functions now take an optional ``symlinks`` argument: when that |
| 1796 | parameter is true, symlinks aren't dereferenced and the operation instead |
| 1797 | acts on the symlink itself (or creates one, if relevant). |
| 1798 | (Contributed by Hynek Schlawack in :issue:`12715`.) |
| 1799 | |
Nick Coghlan | 5b0eca1 | 2012-06-24 16:43:06 +1000 | [diff] [blame] | 1800 | * :func:`~shutil.rmtree` is now resistant to symlink attacks on platforms |
| 1801 | which support the new ``dir_fd`` parameter in :func:`os.open` and |
Georg Brandl | dba3b5c | 2012-06-26 09:36:14 +0200 | [diff] [blame] | 1802 | :func:`os.unlink`. (Contributed by Martin von Löwis and Hynek Schlawack |
Nick Coghlan | 5b0eca1 | 2012-06-24 16:43:06 +1000 | [diff] [blame] | 1803 | in :issue:`4489`.) |
| 1804 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 1805 | |
Victor Stinner | a929335 | 2011-04-30 15:21:58 +0200 | [diff] [blame] | 1806 | signal |
| 1807 | ------ |
| 1808 | |
Victor Stinner | fa0e3d5 | 2011-05-09 01:01:09 +0200 | [diff] [blame] | 1809 | * The :mod:`signal` module has new functions: |
Victor Stinner | a929335 | 2011-04-30 15:21:58 +0200 | [diff] [blame] | 1810 | |
Victor Stinner | b3e7219 | 2011-05-08 01:46:11 +0200 | [diff] [blame] | 1811 | * :func:`~signal.pthread_sigmask`: fetch and/or change the signal mask of the |
| 1812 | calling thread (Contributed by Jean-Paul Calderone in :issue:`8407`) ; |
| 1813 | * :func:`~signal.pthread_kill`: send a signal to a thread ; |
| 1814 | * :func:`~signal.sigpending`: examine pending functions ; |
| 1815 | * :func:`~signal.sigwait`: wait a signal. |
Ross Lagerwall | bc80822 | 2011-06-25 12:13:40 +0200 | [diff] [blame] | 1816 | * :func:`~signal.sigwaitinfo`: wait for a signal, returning detailed |
| 1817 | information about it. |
| 1818 | * :func:`~signal.sigtimedwait`: like :func:`~signal.sigwaitinfo` but with a |
| 1819 | timeout. |
Victor Stinner | a929335 | 2011-04-30 15:21:58 +0200 | [diff] [blame] | 1820 | |
Victor Stinner | d49b1f1 | 2011-05-08 02:03:15 +0200 | [diff] [blame] | 1821 | * The signal handler writes the signal number as a single byte instead of |
| 1822 | a nul byte into the wakeup file descriptor. So it is possible to wait more |
| 1823 | than one signal and know which signals were raised. |
| 1824 | |
Victor Stinner | 388196e | 2011-05-10 17:13:00 +0200 | [diff] [blame] | 1825 | * :func:`signal.signal` and :func:`signal.siginterrupt` raise an OSError, |
| 1826 | instead of a RuntimeError: OSError has an errno attribute. |
| 1827 | |
R David Murray | 1764c80 | 2012-09-29 11:42:36 -0400 | [diff] [blame] | 1828 | |
| 1829 | smtpd |
| 1830 | ----- |
| 1831 | |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 1832 | The :mod:`smtpd` module now supports :rfc:`5321` (extended SMTP) and :rfc:`1870` |
| 1833 | (size extension). Per the standard, these extensions are enabled if and only |
| 1834 | if the client initiates the session with an ``EHLO`` command. |
R David Murray | 1764c80 | 2012-09-29 11:42:36 -0400 | [diff] [blame] | 1835 | |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 1836 | (Initial ``ELHO`` support by Alberto Trevino. Size extension by Juhana |
| 1837 | Jauhiainen. Substantial additional work on the patch contributed by Michele |
| 1838 | Orrù and Dan Boswell. :issue:`8739`) |
R David Murray | 1764c80 | 2012-09-29 11:42:36 -0400 | [diff] [blame] | 1839 | |
| 1840 | |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 1841 | smtplib |
| 1842 | ------- |
| 1843 | |
R David Murray | a21e515 | 2012-10-06 16:29:14 -0400 | [diff] [blame] | 1844 | The :class:`~smtplib.SMTP`, :class:`~smtplib.SMTP_SSL`, and |
| 1845 | :class:`~smtplib.LMTP` classes now accept a ``source_address`` keyword argument |
| 1846 | to specify the ``(host, port)`` to use as the source address in the bind call |
| 1847 | when creating the outgoing socket. (Contributed by Paulo Scardine in |
| 1848 | :issue:`11281`.) |
| 1849 | |
R David Murray | 3430fb8 | 2012-10-02 18:24:56 -0400 | [diff] [blame] | 1850 | :class:`~smtplib.SMTP` now supports the context manager protocol, allowing an |
| 1851 | ``SMTP`` instance to be used in a ``with`` statement. (Contributed |
| 1852 | by Giampaolo Rodolà in :issue:`11289`.) |
| 1853 | |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 1854 | The :class:`~smtplib.SMTP_SSL` constructor and the :meth:`~smtplib.SMTP.starttls` |
| 1855 | method now accept an SSLContext parameter to control parameters of the secure |
R David Murray | 3430fb8 | 2012-10-02 18:24:56 -0400 | [diff] [blame] | 1856 | channel. (Contributed by Kasun Herath in :issue:`8809`) |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 1857 | |
| 1858 | |
Nick Coghlan | 96fe56a | 2011-08-22 11:55:57 +1000 | [diff] [blame] | 1859 | socket |
| 1860 | ------ |
| 1861 | |
Charles-François Natali | 47413c1 | 2011-10-06 19:47:44 +0200 | [diff] [blame] | 1862 | * The :class:`~socket.socket` class now exposes additional methods to process |
| 1863 | ancillary data when supported by the underlying platform: |
Nick Coghlan | 96fe56a | 2011-08-22 11:55:57 +1000 | [diff] [blame] | 1864 | |
Charles-François Natali | 47413c1 | 2011-10-06 19:47:44 +0200 | [diff] [blame] | 1865 | * :func:`~socket.socket.sendmsg` |
| 1866 | * :func:`~socket.socket.recvmsg` |
| 1867 | * :func:`~socket.socket.recvmsg_into` |
Nick Coghlan | 96fe56a | 2011-08-22 11:55:57 +1000 | [diff] [blame] | 1868 | |
Charles-François Natali | 47413c1 | 2011-10-06 19:47:44 +0200 | [diff] [blame] | 1869 | (Contributed by David Watson in :issue:`6560`, based on an earlier patch by |
| 1870 | Heiko Wundram) |
| 1871 | |
| 1872 | * The :class:`~socket.socket` class now supports the PF_CAN protocol family |
| 1873 | (http://en.wikipedia.org/wiki/Socketcan), on Linux |
| 1874 | (http://lwn.net/Articles/253425). |
| 1875 | |
| 1876 | (Contributed by Matthias Fuchs, updated by Tiago Gonçalves in :issue:`10141`) |
| 1877 | |
Charles-François Natali | 10b8cf4 | 2011-11-10 19:21:37 +0100 | [diff] [blame] | 1878 | * The :class:`~socket.socket` class now supports the PF_RDS protocol family |
| 1879 | (http://en.wikipedia.org/wiki/Reliable_Datagram_Sockets and |
| 1880 | http://oss.oracle.com/projects/rds/). |
Victor Stinner | 754851f | 2011-04-19 23:58:51 +0200 | [diff] [blame] | 1881 | |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 1882 | * New function :func:`~socket.sethostname` allows the hostname to be set |
| 1883 | on unix systems if the calling process has sufficient privileges. |
| 1884 | (Contributed by Ross Lagerwall in :issue:`10866`.) |
| 1885 | |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 1886 | |
R David Murray | 258fabe | 2012-10-01 21:43:46 -0400 | [diff] [blame] | 1887 | socketserver |
| 1888 | ------------ |
| 1889 | |
| 1890 | :class:`~socketserver.BaseServer` now has an overridable method |
| 1891 | :meth:`~socketserver.BaseServer.service_actions` that is called by the |
| 1892 | :meth:`~socketserver.BaseServer.serve_forever` method in the service loop. |
| 1893 | :class:`~socketserver.ForkingMixIn` now uses this to clean up zombie |
| 1894 | child proceses. (Contributed by Justin Warkentin in :issue:`11109`.) |
| 1895 | |
| 1896 | |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1897 | sqlite3 |
| 1898 | ------- |
| 1899 | |
| 1900 | New :class:`sqlite3.Connection` method |
| 1901 | :meth:`~sqlite3.Connection.set_trace_callback` can be used to capture a trace of |
| 1902 | all sql commands processed by sqlite. (Contributed by Torsten Landschoff |
| 1903 | in :issue:`11688`.) |
| 1904 | |
| 1905 | |
Victor Stinner | 99c8b16 | 2011-05-24 12:05:19 +0200 | [diff] [blame] | 1906 | ssl |
| 1907 | --- |
| 1908 | |
Antoine Pitrou | 2c0a967 | 2011-11-17 02:09:13 +0100 | [diff] [blame] | 1909 | * The :mod:`ssl` module has two new random generation functions: |
Victor Stinner | 99c8b16 | 2011-05-24 12:05:19 +0200 | [diff] [blame] | 1910 | |
| 1911 | * :func:`~ssl.RAND_bytes`: generate cryptographically strong |
| 1912 | pseudo-random bytes. |
| 1913 | * :func:`~ssl.RAND_pseudo_bytes`: generate pseudo-random bytes. |
| 1914 | |
Antoine Pitrou | 2c0a967 | 2011-11-17 02:09:13 +0100 | [diff] [blame] | 1915 | (Contributed by Victor Stinner in :issue:`12049`) |
| 1916 | |
| 1917 | * The :mod:`ssl` module now exposes a finer-grained exception hierarchy |
| 1918 | in order to make it easier to inspect the various kinds of errors. |
Antoine Pitrou | 2c0a967 | 2011-11-17 02:09:13 +0100 | [diff] [blame] | 1919 | (Contributed by Antoine Pitrou in :issue:`11183`) |
| 1920 | |
| 1921 | * :meth:`~ssl.SSLContext.load_cert_chain` now accepts a *password* argument |
| 1922 | to be used if the private key is encrypted. |
Antoine Pitrou | 2c0a967 | 2011-11-17 02:09:13 +0100 | [diff] [blame] | 1923 | (Contributed by Adam Simpkins in :issue:`12803`) |
| 1924 | |
Antoine Pitrou | 73fc814 | 2011-12-23 20:58:36 +0100 | [diff] [blame] | 1925 | * Diffie-Hellman key exchange, both regular and Elliptic Curve-based, is |
| 1926 | now supported through the :meth:`~ssl.SSLContext.load_dh_params` and |
| 1927 | :meth:`~ssl.SSLContext.set_ecdh_curve` methods. |
Antoine Pitrou | 73fc814 | 2011-12-23 20:58:36 +0100 | [diff] [blame] | 1928 | (Contributed by Antoine Pitrou in :issue:`13626` and :issue:`13627`) |
| 1929 | |
Antoine Pitrou | 2c0a967 | 2011-11-17 02:09:13 +0100 | [diff] [blame] | 1930 | * SSL sockets have a new :meth:`~ssl.SSLSocket.get_channel_binding` method |
| 1931 | allowing the implementation of certain authentication mechanisms such as |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1932 | SCRAM-SHA-1-PLUS. (Contributed by Jacek Konieczny in :issue:`12551`) |
Antoine Pitrou | 2c0a967 | 2011-11-17 02:09:13 +0100 | [diff] [blame] | 1933 | |
Antoine Pitrou | 73fc814 | 2011-12-23 20:58:36 +0100 | [diff] [blame] | 1934 | * You can query the SSL compression algorithm used by an SSL socket, thanks |
R David Murray | fd74096 | 2012-10-06 22:08:08 -0400 | [diff] [blame] | 1935 | to its new :meth:`~ssl.SSLSocket.compression` method. The new attribute |
| 1936 | :attr:`~ssl.OP_NO_COMPRESSION` can be used to disable compression. |
Antoine Pitrou | 73fc814 | 2011-12-23 20:58:36 +0100 | [diff] [blame] | 1937 | (Contributed by Antoine Pitrou in :issue:`13634`) |
| 1938 | |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 1939 | * Support has been added for the Next Procotol Negotiation extension using |
| 1940 | the :meth:`ssl.SSLContext.set_npn_protocols` method. |
Antoine Pitrou | 9a86447 | 2012-05-04 23:15:47 +0200 | [diff] [blame] | 1941 | (Contributed by Colin Marc in :issue:`14204`) |
| 1942 | |
Antoine Pitrou | ad09b5d | 2012-06-24 22:41:33 +0200 | [diff] [blame] | 1943 | * SSL errors can now be introspected more easily thanks to |
| 1944 | :attr:`~ssl.SSLError.library` and :attr:`~ssl.SSLError.reason` attributes. |
Antoine Pitrou | ad09b5d | 2012-06-24 22:41:33 +0200 | [diff] [blame] | 1945 | (Contributed by Antoine Pitrou in :issue:`14837`) |
| 1946 | |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1947 | * The :func:`~ssl.get_server_certificate` function now supports IPv6. |
| 1948 | (Contributed by Charles-François Natali in :issue:`11811`.) |
| 1949 | |
R David Murray | fd74096 | 2012-10-06 22:08:08 -0400 | [diff] [blame] | 1950 | * New attribute :attr:`~ssl.OP_CIPHER_SERVER_PREFERENCE` allows setting |
| 1951 | SSLv3 server sockets to use the server's cipher ordering preference rather |
| 1952 | than the client's (:issue:`13635`). |
| 1953 | |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1954 | |
Giampaolo Rodola' | ffa1d0b | 2012-05-15 15:30:25 +0200 | [diff] [blame] | 1955 | stat |
| 1956 | ---- |
| 1957 | |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 1958 | The undocumented tarfile.filemode function has been moved to |
| 1959 | :func:`stat.filemode`. It can be used to convert a file's mode to a string of |
| 1960 | the form '-rwxrwxrwx'. |
Giampaolo Rodola' | ffa1d0b | 2012-05-15 15:30:25 +0200 | [diff] [blame] | 1961 | |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 1962 | (Contributed by Giampaolo Rodolà in :issue:`14807`) |
Antoine Pitrou | 73fc814 | 2011-12-23 20:58:36 +0100 | [diff] [blame] | 1963 | |
R David Murray | c652ce6 | 2012-09-30 20:07:42 -0400 | [diff] [blame] | 1964 | |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 1965 | struct |
| 1966 | ------ |
| 1967 | |
| 1968 | The :mod:`struct` module now supports ``ssize_t`` and ``size_t`` via the |
| 1969 | new codes ``n`` and ``N``, respectively. (Contributed by Antoine Pitrou |
| 1970 | in :issue:`3163`.) |
| 1971 | |
| 1972 | |
R David Murray | c652ce6 | 2012-09-30 20:07:42 -0400 | [diff] [blame] | 1973 | subprocess |
| 1974 | ---------- |
| 1975 | |
| 1976 | Command strings can now be bytes objects on posix platforms. (Contributed by |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1977 | Victor Stinner in :issue:`8513`.) |
R David Murray | c652ce6 | 2012-09-30 20:07:42 -0400 | [diff] [blame] | 1978 | |
| 1979 | A new constant :data:`~subprocess.DEVNULL` allows suppressing output in a |
| 1980 | platform-independent fashion. (Contributed by Ross Lagerwall in |
| 1981 | :issue:`5870`.) |
| 1982 | |
| 1983 | |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 1984 | sys |
| 1985 | --- |
Giampaolo Rodola' | 210e7ca | 2011-07-01 13:55:36 +0200 | [diff] [blame] | 1986 | |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 1987 | The :mod:`sys` module has a new :data:`~sys.thread_info` :term:`struct |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 1988 | sequence` holding informations about the thread implementation |
| 1989 | (:issue:`11223`). |
Giampaolo Rodola' | 096dcb1 | 2011-06-27 11:17:51 +0200 | [diff] [blame] | 1990 | |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 1991 | |
R David Murray | fd74096 | 2012-10-06 22:08:08 -0400 | [diff] [blame] | 1992 | tarfile |
| 1993 | ------- |
| 1994 | |
| 1995 | :mod:`tarfile` now supports ``lzma`` encoding via the :mod:`lzma` module. |
| 1996 | (Contributed by Lars Gustäbel in :issue:`5689`.) |
| 1997 | |
| 1998 | |
R David Murray | ca76ea1 | 2012-10-06 18:32:39 -0400 | [diff] [blame] | 1999 | tempfile |
| 2000 | -------- |
| 2001 | |
| 2002 | :class:`tempfile.SpooledTemporaryFile`\'s |
| 2003 | :meth:`~tempfile.SpooledTemporaryFile.trucate` method now accepts |
| 2004 | a ``size`` parameter. (Contributed by Ryan Kelly in :issue:`9957`.) |
| 2005 | |
| 2006 | |
Nick Coghlan | 4fae8cd | 2012-06-11 23:07:51 +1000 | [diff] [blame] | 2007 | textwrap |
| 2008 | -------- |
| 2009 | |
R David Murray | 26d15bf | 2012-09-29 15:13:35 -0400 | [diff] [blame] | 2010 | The :mod:`textwrap` module has a new :func:`~textwrap.indent` that makes |
| 2011 | it straightforward to add a common prefix to selected lines in a block |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 2012 | of text (:issue:`13857`). |
Antoine Pitrou | 5a8bc6f | 2011-11-17 02:20:48 +0100 | [diff] [blame] | 2013 | |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 2014 | |
| 2015 | threading |
| 2016 | --------- |
| 2017 | |
R David Murray | ef4d286 | 2012-10-06 14:35:35 -0400 | [diff] [blame] | 2018 | :class:`threading.Condition`, :class:`threading.Semaphore`, |
R David Murray | 344174d | 2012-10-06 16:06:16 -0400 | [diff] [blame] | 2019 | :class:`threading.BoundedSemaphore`, :class:`threading.Event`, and |
R David Murray | ef4d286 | 2012-10-06 14:35:35 -0400 | [diff] [blame] | 2020 | :class:`threading.Timer`, all of which used to be factory functions returning a |
| 2021 | class instance, are now classes and may be subclassed. (Contributed by Éric |
R David Murray | 344174d | 2012-10-06 16:06:16 -0400 | [diff] [blame] | 2022 | Araujo in :issue:`10968`). |
R David Murray | ef4d286 | 2012-10-06 14:35:35 -0400 | [diff] [blame] | 2023 | |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 2024 | The :class:`threading.Thread` constructor now accepts a ``daemon`` keyword |
| 2025 | argument to override the default behavior of inheriting the ``deamon`` flag |
| 2026 | value from the parent thread (:issue:`6064`). |
| 2027 | |
R David Murray | 0bbfd6b | 2012-10-01 22:10:15 -0400 | [diff] [blame] | 2028 | The formerly private function ``_thread.get_ident`` is now available as the |
Georg Brandl | dc704c6 | 2012-10-02 10:16:19 +0200 | [diff] [blame] | 2029 | public function :func:`threading.get_ident`. This eliminates several cases of |
R David Murray | 0bbfd6b | 2012-10-01 22:10:15 -0400 | [diff] [blame] | 2030 | direct access to the ``_thread`` module in the stdlib. Third party code that |
| 2031 | used ``_thread.get_ident`` should likewise be changed to use the new public |
| 2032 | interface. |
| 2033 | |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 2034 | |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 2035 | time |
| 2036 | ---- |
Antoine Pitrou | 5a8bc6f | 2011-11-17 02:20:48 +0100 | [diff] [blame] | 2037 | |
Victor Stinner | ec89539 | 2012-04-29 02:41:27 +0200 | [diff] [blame] | 2038 | The :pep:`418` added new functions to the :mod:`time` module: |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 2039 | |
Victor Stinner | ec89539 | 2012-04-29 02:41:27 +0200 | [diff] [blame] | 2040 | * :func:`~time.get_clock_info`: Get information on a clock. |
| 2041 | * :func:`~time.monotonic`: Monotonic clock (cannot go backward), not affected |
| 2042 | by system clock updates. |
| 2043 | * :func:`~time.perf_counter`: Performance counter with the highest available |
| 2044 | resolution to measure a short duration. |
| 2045 | * :func:`~time.process_time`: Sum of the system and user CPU time of the |
| 2046 | current process. |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 2047 | |
Victor Stinner | ec89539 | 2012-04-29 02:41:27 +0200 | [diff] [blame] | 2048 | Other new functions: |
| 2049 | |
| 2050 | * :func:`~time.clock_getres`, :func:`~time.clock_gettime` and |
| 2051 | :func:`~time.clock_settime` functions with ``CLOCK_xxx`` constants. |
| 2052 | (Contributed by Victor Stinner in :issue:`10278`) |
Victor Stinner | f4c54ff | 2012-02-08 01:48:34 +0100 | [diff] [blame] | 2053 | |
R David Murray | 3430fb8 | 2012-10-02 18:24:56 -0400 | [diff] [blame] | 2054 | To improve cross platform consistency, :func:`~time.sleep` now raises a |
| 2055 | :exc:`ValueError` when passed a negative sleep value. Previously this was an |
| 2056 | error on posix, but produced an infinite sleep on Windows. |
| 2057 | |
Antoine Pitrou | 5a8bc6f | 2011-11-17 02:20:48 +0100 | [diff] [blame] | 2058 | |
Victor Stinner | 0db176f | 2012-04-16 00:16:30 +0200 | [diff] [blame] | 2059 | types |
| 2060 | ----- |
| 2061 | |
| 2062 | Add a new :class:`types.MappingProxyType` class: Read-only proxy of a mapping. |
| 2063 | (:issue:`14386`) |
| 2064 | |
| 2065 | |
Nick Coghlan | 7fc570a | 2012-05-20 02:34:13 +1000 | [diff] [blame] | 2066 | The new functions `types.new_class` and `types.prepare_class` provide support |
| 2067 | for PEP 3115 compliant dynamic type creation. (:issue:`14588`) |
| 2068 | |
| 2069 | |
Ezio Melotti | 461f41d | 2012-09-26 17:43:23 +0300 | [diff] [blame] | 2070 | unittest |
| 2071 | -------- |
| 2072 | |
| 2073 | :meth:`.assertRaises`, :meth:`.assertRaisesRegex`, :meth:`.assertWarns`, and |
| 2074 | :meth:`.assertWarnsRegex` now accept a keyword argument *msg* when used as |
R David Murray | c652ce6 | 2012-09-30 20:07:42 -0400 | [diff] [blame] | 2075 | context managers. (Contributed by Ezio Melotti and Winston Ewert in |
| 2076 | :issue:`10775`) |
Ezio Melotti | 461f41d | 2012-09-26 17:43:23 +0300 | [diff] [blame] | 2077 | |
R David Murray | c652ce6 | 2012-09-30 20:07:42 -0400 | [diff] [blame] | 2078 | :meth:`unittest.TestCase.run` now returns the :class:`~unittest.TestResult` |
| 2079 | object. |
Ezio Melotti | 461f41d | 2012-09-26 17:43:23 +0300 | [diff] [blame] | 2080 | |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 2081 | |
Senthil Kumaran | de49d64 | 2011-10-16 23:54:44 +0800 | [diff] [blame] | 2082 | urllib |
| 2083 | ------ |
| 2084 | |
| 2085 | The :class:`~urllib.request.Request` class, now accepts a *method* argument |
| 2086 | used by :meth:`~urllib.request.Request.get_method` to determine what HTTP method |
Senthil Kumaran | a41c942 | 2011-10-20 02:37:08 +0800 | [diff] [blame] | 2087 | should be used. For example, this will send a ``'HEAD'`` request:: |
Senthil Kumaran | de49d64 | 2011-10-16 23:54:44 +0800 | [diff] [blame] | 2088 | |
| 2089 | >>> urlopen(Request('http://www.python.org', method='HEAD')) |
| 2090 | |
| 2091 | (:issue:`1673007`) |
Giampaolo Rodola' | 096dcb1 | 2011-06-27 11:17:51 +0200 | [diff] [blame] | 2092 | |
Giampaolo Rodola' | be55d99 | 2011-11-22 13:33:34 +0100 | [diff] [blame] | 2093 | |
Éric Araujo | 4f61a2d | 2012-04-04 23:01:01 -0400 | [diff] [blame] | 2094 | webbrowser |
| 2095 | ---------- |
| 2096 | |
| 2097 | The :mod:`webbrowser` module supports more browsers: Google Chrome (named |
| 2098 | :program:`chrome`, :program:`chromium`, :program:`chrome-browser` or |
| 2099 | :program:`chromium-browser` depending on the version and operating system) as |
| 2100 | well as the the generic launchers :program:`xdg-open` from the FreeDesktop.org |
| 2101 | project and :program:`gvfs-open` which is the default URI handler for GNOME 3. |
| 2102 | |
| 2103 | (:issue:`13620` and :issue:`14493`) |
| 2104 | |
| 2105 | |
Eli Bendersky | efcaba0 | 2012-08-09 08:20:20 +0300 | [diff] [blame] | 2106 | xml.etree.ElementTree |
| 2107 | --------------------- |
| 2108 | |
| 2109 | The :mod:`xml.etree.ElementTree` module now imports its C accelerator by |
| 2110 | default; there is no longer a need to explicitly import |
| 2111 | :mod:`xml.etree.cElementTree` (this module stays for backwards compatibility, |
| 2112 | but is now deprecated). In addition, the ``iter`` family of methods of |
| 2113 | :class:`~xml.etree.ElementTree.Element` has been optimized (rewritten in C). |
| 2114 | The module's documentation has also been greatly improved with added examples |
| 2115 | and a more detailed reference. |
| 2116 | |
| 2117 | |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 2118 | zlib |
| 2119 | ---- |
| 2120 | |
| 2121 | New attribute :attr:`zlib.Decompress.eof` makes it possible to distinguish |
| 2122 | between a properly-formed compressed stream and an incomplete or truncated one. |
| 2123 | (Contributed by Nadeem Vawda in :issue:`12646`.) |
| 2124 | |
| 2125 | New attribute :attr:`zlib.ZLIB_RUNTIME_VERSION` reports the version string of |
| 2126 | the underlying ``zlib`` library that is loaded at runtime. (Contributed by |
| 2127 | Torsten Landschoff in :issue:`12306`.) |
| 2128 | |
| 2129 | |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 2130 | Optimizations |
| 2131 | ============= |
| 2132 | |
| 2133 | Major performance enhancements have been added: |
| 2134 | |
Éric Araujo | 4f61a2d | 2012-04-04 23:01:01 -0400 | [diff] [blame] | 2135 | * Thanks to :pep:`393`, some operations on Unicode strings have been optimized: |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2136 | |
| 2137 | * the memory footprint is divided by 2 to 4 depending on the text |
Victor Stinner | a996f1e | 2011-11-21 13:14:43 +0100 | [diff] [blame] | 2138 | * encode an ASCII string to UTF-8 doesn't need to encode characters anymore, |
| 2139 | the UTF-8 representation is shared with the ASCII representation |
Victor Stinner | 6099a03 | 2011-12-18 14:22:26 +0100 | [diff] [blame] | 2140 | * the UTF-8 encoder has been optimized |
| 2141 | * repeating a single ASCII letter and getting a substring of a ASCII strings |
| 2142 | is 4 times faster |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 2143 | |
Antoine Pitrou | 5d7e1d3 | 2012-06-24 22:38:23 +0200 | [diff] [blame] | 2144 | * UTF-8 is now 2x to 4x faster. UTF-16 encoding is now up to 10x faster. |
Antoine Pitrou | 5cec9d2 | 2012-05-17 17:37:02 +0200 | [diff] [blame] | 2145 | |
Antoine Pitrou | c909296 | 2012-06-15 22:22:18 +0200 | [diff] [blame] | 2146 | (contributed by Serhiy Storchaka, :issue:`14624`, :issue:`14738` and |
| 2147 | :issue:`15026`.) |
Antoine Pitrou | 5cec9d2 | 2012-05-17 17:37:02 +0200 | [diff] [blame] | 2148 | |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 2149 | |
| 2150 | Build and C API Changes |
| 2151 | ======================= |
| 2152 | |
| 2153 | Changes to Python's build process and to the C API include: |
| 2154 | |
Stefan Krah | 95b1ba6 | 2012-02-29 17:27:21 +0100 | [diff] [blame] | 2155 | * New :pep:`3118` related function: |
| 2156 | |
| 2157 | * :c:func:`PyMemoryView_FromMemory` |
| 2158 | |
Éric Araujo | 4f61a2d | 2012-04-04 23:01:01 -0400 | [diff] [blame] | 2159 | * :pep:`393` added new Unicode types, macros and functions: |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2160 | |
Victor Stinner | a996f1e | 2011-11-21 13:14:43 +0100 | [diff] [blame] | 2161 | * High-level API: |
| 2162 | |
| 2163 | * :c:func:`PyUnicode_CopyCharacters` |
| 2164 | * :c:func:`PyUnicode_FindChar` |
| 2165 | * :c:func:`PyUnicode_GetLength`, :c:macro:`PyUnicode_GET_LENGTH` |
| 2166 | * :c:func:`PyUnicode_New` |
| 2167 | * :c:func:`PyUnicode_Substring` |
| 2168 | * :c:func:`PyUnicode_ReadChar`, :c:func:`PyUnicode_WriteChar` |
| 2169 | |
| 2170 | * Low-level API: |
| 2171 | |
| 2172 | * :c:type:`Py_UCS1`, :c:type:`Py_UCS2`, :c:type:`Py_UCS4` types |
| 2173 | * :c:type:`PyASCIIObject` and :c:type:`PyCompactUnicodeObject` structures |
| 2174 | * :c:macro:`PyUnicode_READY` |
| 2175 | * :c:func:`PyUnicode_FromKindAndData` |
| 2176 | * :c:func:`PyUnicode_AsUCS4`, :c:func:`PyUnicode_AsUCS4Copy` |
| 2177 | * :c:macro:`PyUnicode_DATA`, :c:macro:`PyUnicode_1BYTE_DATA`, |
| 2178 | :c:macro:`PyUnicode_2BYTE_DATA`, :c:macro:`PyUnicode_4BYTE_DATA` |
| 2179 | * :c:macro:`PyUnicode_KIND` with :c:type:`PyUnicode_Kind` enum: |
| 2180 | :c:data:`PyUnicode_WCHAR_KIND`, :c:data:`PyUnicode_1BYTE_KIND`, |
| 2181 | :c:data:`PyUnicode_2BYTE_KIND`, :c:data:`PyUnicode_4BYTE_KIND` |
| 2182 | * :c:macro:`PyUnicode_READ`, :c:macro:`PyUnicode_READ_CHAR`, :c:macro:`PyUnicode_WRITE` |
| 2183 | * :c:macro:`PyUnicode_MAX_CHAR_VALUE` |
| 2184 | |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 2185 | |
| 2186 | |
Victor Stinner | d1be878 | 2011-12-09 00:10:41 +0100 | [diff] [blame] | 2187 | Deprecated |
| 2188 | ========== |
| 2189 | |
Georg Brandl | 0cd25c9 | 2011-04-29 13:45:54 +0200 | [diff] [blame] | 2190 | Unsupported Operating Systems |
Victor Stinner | d1be878 | 2011-12-09 00:10:41 +0100 | [diff] [blame] | 2191 | ----------------------------- |
Victor Stinner | b90db4c | 2011-04-26 22:48:24 +0200 | [diff] [blame] | 2192 | |
Brian Curtin | 49a40cd | 2011-05-02 22:30:06 -0500 | [diff] [blame] | 2193 | OS/2 and VMS are no longer supported due to the lack of a maintainer. |
| 2194 | |
| 2195 | Windows 2000 and Windows platforms which set ``COMSPEC`` to ``command.com`` |
| 2196 | are no longer supported due to maintenance burden. |
Victor Stinner | b90db4c | 2011-04-26 22:48:24 +0200 | [diff] [blame] | 2197 | |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 2198 | OSF support, which was deprecated in 3.2, has been completely removed. |
| 2199 | |
Victor Stinner | b90db4c | 2011-04-26 22:48:24 +0200 | [diff] [blame] | 2200 | |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2201 | Deprecated Python modules, functions and methods |
Victor Stinner | d1be878 | 2011-12-09 00:10:41 +0100 | [diff] [blame] | 2202 | ------------------------------------------------ |
Victor Stinner | 19bd069 | 2011-11-16 00:18:57 +0100 | [diff] [blame] | 2203 | |
Victor Stinner | 19bd069 | 2011-11-16 00:18:57 +0100 | [diff] [blame] | 2204 | * The ``unicode_internal`` codec has been deprecated because of the |
Sandro Tosi | cd89912 | 2012-01-22 12:16:04 +0100 | [diff] [blame] | 2205 | :pep:`393`, use UTF-8, UTF-16 (``utf-16-le`` or ``utf-16-be``), or UTF-32 |
| 2206 | (``utf-32-le`` or ``utf-32-be``) |
Victor Stinner | 19bd069 | 2011-11-16 00:18:57 +0100 | [diff] [blame] | 2207 | * :meth:`ftplib.FTP.nlst` and :meth:`ftplib.FTP.dir`: use |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2208 | :meth:`ftplib.FTP.mlsd` |
Victor Stinner | 19bd069 | 2011-11-16 00:18:57 +0100 | [diff] [blame] | 2209 | * :func:`platform.popen`: use the :mod:`subprocess` module. Check especially |
R David Murray | c652ce6 | 2012-09-30 20:07:42 -0400 | [diff] [blame] | 2210 | the :ref:`subprocess-replacements` section (:issue:`11377`). |
Victor Stinner | 19bd069 | 2011-11-16 00:18:57 +0100 | [diff] [blame] | 2211 | * :issue:`13374`: The Windows bytes API has been deprecated in the :mod:`os` |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2212 | module. Use Unicode filenames, instead of bytes filenames, to not depend on |
Victor Stinner | 19bd069 | 2011-11-16 00:18:57 +0100 | [diff] [blame] | 2213 | the ANSI code page anymore and to support any filename. |
Florent Xicluna | a72a98f | 2012-02-13 11:03:30 +0100 | [diff] [blame] | 2214 | * :issue:`13988`: The :mod:`xml.etree.cElementTree` module is deprecated. The |
| 2215 | accelerator is used automatically whenever available. |
Victor Stinner | 47620a6 | 2012-04-29 02:52:39 +0200 | [diff] [blame] | 2216 | * The behaviour of :func:`time.clock` depends on the platform: use the new |
| 2217 | :func:`time.perf_counter` or :func:`time.process_time` function instead, |
| 2218 | depending on your requirements, to have a well defined behaviour. |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 2219 | * The :func:`os.stat_float_times` function is deprecated. |
Victor Stinner | 8f17c1c | 2012-08-05 16:31:32 +0200 | [diff] [blame] | 2220 | * :mod:`abc` module: |
| 2221 | |
| 2222 | * :class:`abc.abstractproperty` has been deprecated, use :class:`property` |
| 2223 | with :func:`abc.abstractmethod` instead. |
| 2224 | * :class:`abc.abstractclassmethod` has been deprecated, use |
| 2225 | :class:`classmethod` with :func:`abc.abstractmethod` instead. |
| 2226 | * :class:`abc.abstractstaticmethod` has been deprecated, use |
| 2227 | :class:`staticmethod` with :func:`abc.abstractmethod` instead. |
| 2228 | |
Georg Brandl | fc34921 | 2012-09-26 13:11:48 +0200 | [diff] [blame] | 2229 | * :mod:`importlib` package: |
Brett Cannon | 288717a | 2012-09-25 15:23:07 -0400 | [diff] [blame] | 2230 | |
| 2231 | * :meth:`importlib.abc.SourceLoader.path_mtime` is now deprecated in favour of |
| 2232 | :meth:`importlib.abc.SourceLoader.path_stats` as bytecode files now store |
| 2233 | both the modification time and size of the source file the bytecode file was |
| 2234 | compiled from. |
| 2235 | |
| 2236 | |
| 2237 | |
Victor Stinner | 19bd069 | 2011-11-16 00:18:57 +0100 | [diff] [blame] | 2238 | |
| 2239 | |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2240 | Deprecated functions and types of the C API |
Victor Stinner | d1be878 | 2011-12-09 00:10:41 +0100 | [diff] [blame] | 2241 | ------------------------------------------- |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2242 | |
Éric Araujo | 4f61a2d | 2012-04-04 23:01:01 -0400 | [diff] [blame] | 2243 | The :c:type:`Py_UNICODE` has been deprecated by :pep:`393` and will be |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2244 | removed in Python 4. All functions using this type are deprecated: |
| 2245 | |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2246 | Unicode functions and methods using :c:type:`Py_UNICODE` and |
| 2247 | :c:type:`Py_UNICODE*` types: |
| 2248 | |
R David Murray | f75e65f | 2012-09-29 15:27:53 -0400 | [diff] [blame] | 2249 | * :c:macro:`PyUnicode_FromUnicode`: use :c:func:`PyUnicode_FromWideChar` or |
| 2250 | :c:func:`PyUnicode_FromKindAndData` |
| 2251 | * :c:macro:`PyUnicode_AS_UNICODE`, :c:func:`PyUnicode_AsUnicode`, |
| 2252 | :c:func:`PyUnicode_AsUnicodeAndSize`: use :c:func:`PyUnicode_AsWideCharString` |
| 2253 | * :c:macro:`PyUnicode_AS_DATA`: use :c:macro:`PyUnicode_DATA` with |
| 2254 | :c:macro:`PyUnicode_READ` and :c:macro:`PyUnicode_WRITE` |
| 2255 | * :c:macro:`PyUnicode_GET_SIZE`, :c:func:`PyUnicode_GetSize`: use |
| 2256 | :c:macro:`PyUnicode_GET_LENGTH` or :c:func:`PyUnicode_GetLength` |
| 2257 | * :c:macro:`PyUnicode_GET_DATA_SIZE`: use |
| 2258 | ``PyUnicode_GET_LENGTH(str) * PyUnicode_KIND(str)`` (only work on ready |
| 2259 | strings) |
| 2260 | * :c:func:`PyUnicode_AsUnicodeCopy`: use :c:func:`PyUnicode_AsUCS4Copy` or |
| 2261 | :c:func:`PyUnicode_AsWideCharString` |
| 2262 | * :c:func:`PyUnicode_GetMax` |
Victor Stinner | ab59594 | 2011-12-17 04:59:06 +0100 | [diff] [blame] | 2263 | |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2264 | |
Victor Stinner | a996f1e | 2011-11-21 13:14:43 +0100 | [diff] [blame] | 2265 | Functions and macros manipulating Py_UNICODE* strings: |
| 2266 | |
R David Murray | f75e65f | 2012-09-29 15:27:53 -0400 | [diff] [blame] | 2267 | * :c:macro:`Py_UNICODE_strlen`: use :c:func:`PyUnicode_GetLength` or |
| 2268 | :c:macro:`PyUnicode_GET_LENGTH` |
| 2269 | * :c:macro:`Py_UNICODE_strcat`: use :c:func:`PyUnicode_CopyCharacters` or |
| 2270 | :c:func:`PyUnicode_FromFormat` |
| 2271 | * :c:macro:`Py_UNICODE_strcpy`, :c:macro:`Py_UNICODE_strncpy`, |
| 2272 | :c:macro:`Py_UNICODE_COPY`: use :c:func:`PyUnicode_CopyCharacters` or |
| 2273 | :c:func:`PyUnicode_Substring` |
| 2274 | * :c:macro:`Py_UNICODE_strcmp`: use :c:func:`PyUnicode_Compare` |
| 2275 | * :c:macro:`Py_UNICODE_strncmp`: use :c:func:`PyUnicode_Tailmatch` |
| 2276 | * :c:macro:`Py_UNICODE_strchr`, :c:macro:`Py_UNICODE_strrchr`: use |
| 2277 | :c:func:`PyUnicode_FindChar` |
| 2278 | * :c:macro:`Py_UNICODE_FILL`: use :c:func:`PyUnicode_Fill` |
| 2279 | * :c:macro:`Py_UNICODE_MATCH` |
Victor Stinner | a996f1e | 2011-11-21 13:14:43 +0100 | [diff] [blame] | 2280 | |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2281 | Encoders: |
| 2282 | |
R David Murray | f75e65f | 2012-09-29 15:27:53 -0400 | [diff] [blame] | 2283 | * :c:func:`PyUnicode_Encode`: use :c:func:`PyUnicode_AsEncodedObject` |
| 2284 | * :c:func:`PyUnicode_EncodeUTF7` |
| 2285 | * :c:func:`PyUnicode_EncodeUTF8`: use :c:func:`PyUnicode_AsUTF8` or |
| 2286 | :c:func:`PyUnicode_AsUTF8String` |
| 2287 | * :c:func:`PyUnicode_EncodeUTF32` |
| 2288 | * :c:func:`PyUnicode_EncodeUTF16` |
| 2289 | * :c:func:`PyUnicode_EncodeUnicodeEscape:` use |
| 2290 | :c:func:`PyUnicode_AsUnicodeEscapeString` |
| 2291 | * :c:func:`PyUnicode_EncodeRawUnicodeEscape:` use |
| 2292 | :c:func:`PyUnicode_AsRawUnicodeEscapeString` |
| 2293 | * :c:func:`PyUnicode_EncodeLatin1`: use :c:func:`PyUnicode_AsLatin1String` |
| 2294 | * :c:func:`PyUnicode_EncodeASCII`: use :c:func:`PyUnicode_AsASCIIString` |
| 2295 | * :c:func:`PyUnicode_EncodeCharmap` |
| 2296 | * :c:func:`PyUnicode_TranslateCharmap` |
| 2297 | * :c:func:`PyUnicode_EncodeMBCS`: use :c:func:`PyUnicode_AsMBCSString` or |
| 2298 | :c:func:`PyUnicode_EncodeCodePage` (with ``CP_ACP`` code_page) |
| 2299 | * :c:func:`PyUnicode_EncodeDecimal`, |
| 2300 | :c:func:`PyUnicode_TransformDecimalToASCII` |
Victor Stinner | 46606ce | 2011-11-20 18:27:55 +0100 | [diff] [blame] | 2301 | |
| 2302 | |
Stefan Krah | 029780b | 2012-08-24 20:14:12 +0200 | [diff] [blame] | 2303 | Deprecated features |
| 2304 | ------------------- |
| 2305 | |
| 2306 | The :mod:`array` module's ``'u'`` format code is now deprecated and will be |
| 2307 | removed in Python 4 together with the rest of the (:c:type:`Py_UNICODE`) API. |
| 2308 | |
| 2309 | |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 2310 | Porting to Python 3.3 |
| 2311 | ===================== |
| 2312 | |
| 2313 | This section lists previously described changes and other bugfixes |
Antoine Pitrou | 037ffbf | 2011-10-24 00:25:41 +0200 | [diff] [blame] | 2314 | that may require changes to your code. |
| 2315 | |
Barry Warsaw | c1e721b | 2012-07-30 16:24:12 -0400 | [diff] [blame] | 2316 | .. _portingpythoncode: |
| 2317 | |
Antoine Pitrou | 037ffbf | 2011-10-24 00:25:41 +0200 | [diff] [blame] | 2318 | Porting Python code |
| 2319 | ------------------- |
Giampaolo Rodolà | 3108f98 | 2011-02-24 20:59:48 +0000 | [diff] [blame] | 2320 | |
Victor Stinner | fa0d628 | 2012-08-05 15:56:51 +0200 | [diff] [blame] | 2321 | * Hash randomization is enabled by default. Set the :envvar:`PYTHONHASHSEED` |
| 2322 | environment variable to ``0`` to disable hash randomization. See also the |
| 2323 | :meth:`object.__hash__` method. |
Georg Brandl | d6c4340 | 2012-03-07 08:55:52 +0100 | [diff] [blame] | 2324 | |
Victor Stinner | 19bd069 | 2011-11-16 00:18:57 +0100 | [diff] [blame] | 2325 | * :issue:`12326`: On Linux, sys.platform doesn't contain the major version |
Victor Stinner | ff3d939 | 2011-08-20 23:39:26 +0200 | [diff] [blame] | 2326 | anymore. It is now always 'linux', instead of 'linux2' or 'linux3' depending |
| 2327 | on the Linux version used to build Python. Replace sys.platform == 'linux2' |
| 2328 | with sys.platform.startswith('linux'), or directly sys.platform == 'linux' if |
| 2329 | you don't need to support older Python versions. |
Éric Araujo | c09fca6 | 2011-03-23 02:06:24 +0100 | [diff] [blame] | 2330 | |
Victor Stinner | ecc6e66 | 2012-03-14 00:39:29 +0100 | [diff] [blame] | 2331 | * :issue:`13847`, :issue:`14180`: :mod:`time` and :mod:`datetime`: |
| 2332 | :exc:`OverflowError` is now raised instead of :exc:`ValueError` if a |
| 2333 | timestamp is out of range. :exc:`OSError` is now raised if C functions |
| 2334 | :c:func:`gmtime` or :c:func:`localtime` failed. |
| 2335 | |
Brett Cannon | c204348 | 2012-04-29 20:59:41 -0400 | [diff] [blame] | 2336 | * The default finders used by import now utilize a cache of what is contained |
| 2337 | within a specific directory. If you create a Python source file or sourceless |
| 2338 | bytecode file, make sure to call :func:`importlib.invalidate_caches` to clear |
| 2339 | out the cache for the finders to notice the new file. |
| 2340 | |
| 2341 | * :exc:`ImportError` now uses the full name of the module that was attemped to |
| 2342 | be imported. Doctests that check ImportErrors' message will need to be |
| 2343 | updated to use the full name of the module instead of just the tail of the |
| 2344 | name. |
| 2345 | |
Ezio Melotti | 7598e18 | 2012-09-20 08:33:53 +0300 | [diff] [blame] | 2346 | * The *index* argument to :func:`__import__` now defaults to 0 instead of -1 |
Brett Cannon | c204348 | 2012-04-29 20:59:41 -0400 | [diff] [blame] | 2347 | and no longer support negative values. It was an oversight when :pep:`328` was |
| 2348 | implemented that the default value remained -1. If you need to continue to |
| 2349 | perform a relative import followed by an absolute import, then perform the |
| 2350 | relative import using an index of 1, followed by another import using an |
| 2351 | index of 0. It is preferred, though, that you use |
| 2352 | :func:`importlib.import_module` rather than call :func:`__import__` directly. |
| 2353 | |
| 2354 | * :func:`__import__` no longer allows one to use an index value other than 0 |
| 2355 | for top-level modules. E.g. ``__import__('sys', level=1)`` is now an error. |
| 2356 | |
| 2357 | * Because :attr:`sys.meta_path` and :attr:`sys.path_hooks` now have finders on |
| 2358 | them by default, you will most likely want to use :meth:`list.insert` instead |
| 2359 | of :meth:`list.append` to add to those lists. |
| 2360 | |
| 2361 | * Because ``None`` is now inserted into :attr:`sys.path_importer_cache`, if you |
| 2362 | are clearing out entries in the dictionary of paths that do not have a |
| 2363 | finder, you will need to remove keys paired with values of ``None`` **and** |
Brett Cannon | 903c27c | 2012-07-09 14:15:32 -0400 | [diff] [blame] | 2364 | :class:`imp.NullImporter` to be backwards-compatible. This will lead to extra |
Brett Cannon | c204348 | 2012-04-29 20:59:41 -0400 | [diff] [blame] | 2365 | overhead on older versions of Python that re-insert ``None`` into |
| 2366 | :attr:`sys.path_importer_cache` where it repesents the use of implicit |
| 2367 | finders, but semantically it should not change anything. |
| 2368 | |
Brett Cannon | 077ef45 | 2012-08-02 17:50:06 -0400 | [diff] [blame] | 2369 | * :class:`importlib.abc.Finder` no longer specifies a `find_module()` abstract |
| 2370 | method that must be implemented. If you were relying on subclasses to |
| 2371 | implement that method, make sure to check for the method's existence first. |
| 2372 | You will probably want to check for `find_loader()` first, though, in the |
| 2373 | case of working with :term:`path entry finders <path entry finder>`. |
| 2374 | |
Nick Coghlan | 6061000 | 2012-07-15 22:39:39 +1000 | [diff] [blame] | 2375 | * :mod:`pkgutil` has been converted to use :mod:`importlib` internally. This |
| 2376 | eliminates many edge cases where the old behaviour of the PEP 302 import |
| 2377 | emulation failed to match the behaviour of the real import system. The |
| 2378 | import emulation itself is still present, but is now deprecated. The |
| 2379 | :func:`pkgutil.iter_importers` and :func:`pkgutil.walk_packages` functions |
| 2380 | special case the standard import hooks so they are still supported even |
| 2381 | though they do not provide the non-standard ``iter_modules()`` method. |
Brett Cannon | 903c27c | 2012-07-09 14:15:32 -0400 | [diff] [blame] | 2382 | |
R David Murray | ea22685 | 2012-09-30 01:27:24 -0400 | [diff] [blame] | 2383 | * A longstanding RFC-compliance bug (:issue:`1079`) in the parsing done by |
| 2384 | :func:`email.header.decode_header` has been fixed. Code that uses the |
| 2385 | standard idiom to convert encoded headers into unicode |
| 2386 | (``str(make_header(decode_header(h))``) will see no change, but code that |
| 2387 | looks at the individual tuples returned by decode_header will see that |
| 2388 | whitespace that precedes or follows ``ASCII`` sections is now included in the |
| 2389 | ``ASCII`` section. Code that builds headers using ``make_header`` should |
| 2390 | also continue to work without change, since ``make_header`` continues to add |
| 2391 | whitespace between ``ASCII`` and non-``ASCII`` sections if it is not already |
| 2392 | present in the input strings. |
| 2393 | |
| 2394 | * :func:`email.utils.formataddr` now does the correct content transfer |
| 2395 | encoding when passed non-``ASCII`` display names. Any code that depended on |
| 2396 | the previous buggy behavior that preserved the non-``ASCII`` unicode in the |
R David Murray | d2489cf | 2012-09-30 17:28:54 -0400 | [diff] [blame] | 2397 | formatted output string will need to be changed (:issue:`1690608`). |
| 2398 | |
| 2399 | * :meth:`poplib.POP3.quit` may now raise protocol errors like all other |
| 2400 | ``poplib`` methods. Code that assumes ``quit`` does not raise |
| 2401 | :exc:`poplib.error_proto` errors may need to be changed if errors on ``quit`` |
| 2402 | are encountered by a particular application (:issue:`11291`). |
R David Murray | ea22685 | 2012-09-30 01:27:24 -0400 | [diff] [blame] | 2403 | |
R David Murray | 445d69c | 2012-09-30 21:59:56 -0400 | [diff] [blame] | 2404 | * The ``strict`` argument to :class:`email.parser.Parser`, deprecated since |
| 2405 | Python 2.4, has finally been removed. |
| 2406 | |
| 2407 | * The deprecated method ``unittest.TestCase.assertSameElements`` has been |
| 2408 | removed. |
| 2409 | |
| 2410 | * The deprecated variable ``time.accept2dyear`` has been removed. |
| 2411 | |
R David Murray | 1e218c9 | 2012-10-06 18:18:55 -0400 | [diff] [blame] | 2412 | * The deprecated ``Context._clamp`` attribute has been removed from the |
| 2413 | :mod:`decimal` module. It was previously replaced by the public attribute |
| 2414 | :attr:`~decimal.Context.clamp`. (See :issue:`8540`.) |
| 2415 | |
R David Murray | 3430fb8 | 2012-10-02 18:24:56 -0400 | [diff] [blame] | 2416 | * The undocumented internal helper class ``SSLFakeFile`` has been removed |
| 2417 | from :mod:`smtplib`, since its functionality has long been provided directly |
| 2418 | by :meth:`socket.socket.makefile`. |
| 2419 | |
| 2420 | * Passing a negative value to :func:`time.sleep` on Windows now raises an |
| 2421 | error instead of sleeping forever. It has always raised an error on posix. |
| 2422 | |
| 2423 | * The ``ast.__version__`` constant has been removed. If you need to |
| 2424 | make decisions affected by the AST version, use :attr:`sys.version_info` |
| 2425 | to make the decision. |
R David Murray | 994ce1a | 2012-10-02 10:19:08 -0400 | [diff] [blame] | 2426 | |
R David Murray | ef4d286 | 2012-10-06 14:35:35 -0400 | [diff] [blame] | 2427 | * Code that used to work around the fact that the :mod:`threading` module used |
| 2428 | factory functions by subclassing the private classes will need to change to |
| 2429 | subclass the now-public classes. |
| 2430 | |
Brett Cannon | c204348 | 2012-04-29 20:59:41 -0400 | [diff] [blame] | 2431 | |
Antoine Pitrou | 037ffbf | 2011-10-24 00:25:41 +0200 | [diff] [blame] | 2432 | Porting C code |
| 2433 | -------------- |
| 2434 | |
Stefan Krah | 54c3203 | 2012-02-29 17:47:21 +0100 | [diff] [blame] | 2435 | * In the course of changes to the buffer API the undocumented |
| 2436 | :c:member:`~Py_buffer.smalltable` member of the |
| 2437 | :c:type:`Py_buffer` structure has been removed and the |
| 2438 | layout of the :c:type:`PyMemoryViewObject` has changed. |
| 2439 | |
| 2440 | All extensions relying on the relevant parts in ``memoryobject.h`` |
| 2441 | or ``object.h`` must be rebuilt. |
| 2442 | |
Antoine Pitrou | 037ffbf | 2011-10-24 00:25:41 +0200 | [diff] [blame] | 2443 | * Due to :ref:`PEP 393 <pep-393>`, the :c:type:`Py_UNICODE` type and all |
| 2444 | functions using this type are deprecated (but will stay available for |
| 2445 | at least five years). If you were using low-level Unicode APIs to |
| 2446 | construct and access unicode objects and you want to benefit of the |
Éric Araujo | 4f61a2d | 2012-04-04 23:01:01 -0400 | [diff] [blame] | 2447 | memory footprint reduction provided by PEP 393, you have to convert |
Antoine Pitrou | 037ffbf | 2011-10-24 00:25:41 +0200 | [diff] [blame] | 2448 | your code to the new :doc:`Unicode API <../c-api/unicode>`. |
| 2449 | |
| 2450 | However, if you only have been using high-level functions such as |
| 2451 | :c:func:`PyUnicode_Concat()`, :c:func:`PyUnicode_Join` or |
| 2452 | :c:func:`PyUnicode_FromFormat()`, your code will automatically take |
| 2453 | advantage of the new unicode representations. |
| 2454 | |
Brett Cannon | 77b2abd | 2012-07-09 16:09:00 -0400 | [diff] [blame] | 2455 | * :c:func:`PyImport_GetMagicNumber` now returns -1 upon failure. |
| 2456 | |
Ezio Melotti | 7598e18 | 2012-09-20 08:33:53 +0300 | [diff] [blame] | 2457 | * As a negative value for the *level* argument to :func:`__import__` is no |
Brett Cannon | 522267e | 2012-08-10 18:55:08 -0400 | [diff] [blame] | 2458 | longer valid, the same now holds for :c:func:`PyImport_ImportModuleLevel`. |
Ezio Melotti | 7598e18 | 2012-09-20 08:33:53 +0300 | [diff] [blame] | 2459 | This also means that the value of *level* used by |
Brett Cannon | 522267e | 2012-08-10 18:55:08 -0400 | [diff] [blame] | 2460 | :c:func:`PyImport_ImportModuleEx` is now 0 instead of -1. |
| 2461 | |
Brett Cannon | 77b2abd | 2012-07-09 16:09:00 -0400 | [diff] [blame] | 2462 | |
Antoine Pitrou | c229e6e | 2012-02-20 19:41:11 +0100 | [diff] [blame] | 2463 | Building C extensions |
| 2464 | --------------------- |
| 2465 | |
| 2466 | * The range of possible file names for C extensions has been narrowed. |
| 2467 | Very rarely used spellings have been suppressed: under POSIX, files |
| 2468 | named ``xxxmodule.so``, ``xxxmodule.abi3.so`` and |
| 2469 | ``xxxmodule.cpython-*.so`` are no longer recognized as implementing |
| 2470 | the ``xxx`` module. If you had been generating such files, you have |
| 2471 | to switch to the other spellings (i.e., remove the ``module`` string |
| 2472 | from the file names). |
| 2473 | |
| 2474 | (implemented in :issue:`14040`.) |
| 2475 | |
| 2476 | |
R David Murray | 1764c80 | 2012-09-29 11:42:36 -0400 | [diff] [blame] | 2477 | Command Line Switch Changes |
| 2478 | --------------------------- |
Antoine Pitrou | 037ffbf | 2011-10-24 00:25:41 +0200 | [diff] [blame] | 2479 | |
R David Murray | 1764c80 | 2012-09-29 11:42:36 -0400 | [diff] [blame] | 2480 | * The -Q command-line flag and related artifacts have been removed. Code |
| 2481 | checking sys.flags.division_warning will need updating. |
Éric Araujo | be3bd57 | 2011-03-26 01:55:15 +0100 | [diff] [blame] | 2482 | |
R David Murray | 1764c80 | 2012-09-29 11:42:36 -0400 | [diff] [blame] | 2483 | (:issue:`10998`, contributed by Éric Araujo.) |
| 2484 | |
| 2485 | * When :program:`python` is started with :option:`-S`, ``import site`` |
| 2486 | will no longer add site-specific paths to the module search paths. In |
| 2487 | previous versions, it did. |
| 2488 | |
| 2489 | (:issue:`11591`, contributed by Carl Meyer with editions by Éric Araujo.) |