diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst index f1dcc579e30..d7a70ab8320 100644 --- a/Doc/whatsnew/2.7.rst +++ b/Doc/whatsnew/2.7.rst @@ -88,8 +88,25 @@ Other Language Changes Some smaller changes made to the core Python language are: +* The string :method:`format` method now supports automatic numbering + of the replacement fields. This makes using :meth:`format` + more closely resemble using ``%s`` formatting:: + + >>> '{}:{}:{}'.format(2009, 04, 'Sunday') + '2009:4:Sunday' + >>> '{}:{}:{day}'.format(2009, 4, day='Sunday') + '2009:4:Sunday' + + The auto-numbering takes the fields from left to right, so the first + ``{...}`` specifier will use the first argument to :meth:`format`, + the next specifier will use the next argument, and so on. You can't + mix auto-numbering and explicit numbering -- either number all of + your specifier fields or none of them -- but you can mix + auto-numbering and named fields, as in the second example above. + (Contributed by XXX; :issue`5237`.) + * The :func:`int` and :func:`long` types gained a ``bit_length`` - method that returns the number of bits necessary to represent +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' method that returns the number of bits necessary to represent its argument in binary:: >>> n = 37 @@ -106,7 +123,7 @@ Some smaller changes made to the core Python language are: (Contributed by Fredrik Johansson and Victor Stinner; :issue:`3439`.) * The :class:`bytearray` type's :meth:`translate` method will - now accept None as its first argument. (Fixed by Georg Brandl; + now accept ``None`` as its first argument. (Fixed by Georg Brandl; :issue:`4759`.) .. ====================================================================== @@ -201,7 +218,7 @@ changes, or look through the Subversion logs for all the details. management protocol, so you can write ``with bz2.BZ2File(...) as f: ...``. (Contributed by Hagen Fuerstenau; :issue:`3860`.) -* A new :class:`Counter` class in the :mod:`collections` module is +* New class: the :class:`Counter` class in the :mod:`collections` module is useful for tallying data. :class:`Counter` instances behave mostly like dictionaries but return zero for missing keys instead of raising a :exc:`KeyError`:: @@ -236,7 +253,7 @@ changes, or look through the Subversion logs for all the details. Contributed by Raymond Hettinger; :issue:`1696199`. The :class:`namedtuple` class now has an optional *rename* parameter. - If *rename* is True, field names that are invalid because they've + If *rename* is true, field names that are invalid because they've been repeated or that aren't legal Python identifiers will be renamed to legal names that are derived from the field's position within the list of fields: @@ -247,8 +264,13 @@ changes, or look through the Subversion logs for all the details. (Added by Raymond Hettinger; :issue:`1818`.) + The :class:`deque` data type now exposes its maximum length as the + read-only :attr:`maxlen` attribute. (Added by Raymond Hettinger.) + * In Distutils, :func:`distutils.sdist.add_defaults` now uses *package_dir* and *data_files* to create the MANIFEST file. + :mod:`distutils.sysconfig` will now read the :envvar:`AR` + environment variable. It is no longer mandatory to store clear-text passwords in the :file:`.pypirc` file when registering and uploading packages to PyPI. As long @@ -256,6 +278,12 @@ changes, or look through the Subversion logs for all the details. prompt for the password if not present. (Added by Tarek Ziade, based on an initial contribution by Nathan Van Gheem; :issue:`4394`.) + A Distutils setup can now specify that a C extension is optional by + setting the *optional* option setting to true. If this optional is + supplied, failure to build the extension will not abort the build + process, but instead simply not install the failing extension. + (Contributed by XXX; :issue:`5583`.) + * New method: the :class:`Decimal` class gained a :meth:`from_float` class method that performs an exact conversion of a floating-point number to a :class:`Decimal`. @@ -267,8 +295,8 @@ changes, or look through the Subversion logs for all the details. ``Decimal('0.1000000000000000055511151231257827021181583404541015625')``. (Implemented by Raymond Hettinger; :issue:`4796`.) -* A new function in the :mod:`gc` module, :func:`is_tracked`, returns - True if a given instance is tracked by the garbage collector, False +* New function: the :mod:`gc` module's :func:`is_tracked` returns + true if a given instance is tracked by the garbage collector, false otherwise. (Contributed by Antoine Pitrou; :issue:`4688`.) * The :mod:`gzip` module's :class:`GzipFile` now supports the context @@ -284,7 +312,7 @@ changes, or look through the Subversion logs for all the details. * New function: ``itertools.compress(*data*, *selectors*)`` takes two iterators. Elements of *data* are returned if the corresponding - value in *selectors* is True:: + value in *selectors* is true:: itertools.compress('ABCDEF', [1,0,1,0,1,1]) => A, C, E, F @@ -332,8 +360,12 @@ changes, or look through the Subversion logs for all the details. uses. You can now do ``help('<<')`` or ``help('@')``, for example. (Contributed by David Laban; :issue:`4739`.) -* A new function in the :mod:`subprocess` module, - :func:`check_output`, runs a command with a specified set of arguments +* The :mod:`re` module's :func:`split`, :func:`sub`, and :func:`subn` + now accept an optional *flags* argument, for consistency with the + other functions in the module. (Added by Gregory P. Smith.) + +* New function: the :mod:`subprocess` module's + :func:`check_output` runs a command with a specified set of arguments and returns the command's output as a string when the command runs without error, or raises a :exc:`CalledProcessError` exception otherwise. @@ -349,13 +381,25 @@ changes, or look through the Subversion logs for all the details. (Contributed by Gregory P. Smith.) +* New function: :func:`is_declared_global` in the :mod:`symtable` module + returns true for variables that are explicitly declared to be global, + false for ones that are implicitly global. + (Contributed by Jeremy Hylton.) + * The ``sys.version_info`` value is now a named tuple, with attributes named ``major``, ``minor``, ``micro``, ``releaselevel``, and ``serial``. (Contributed by Ross Light; :issue:`4285`.) +* The :mod:`threading` module's :meth:`Event.wait` method now returns + the internal flag on exit. This means the method will usually + return true because :meth:`wait` is supposed to block until the + internal flag becomes true. The return value will only be false if + a timeout was provided and the operation timed out. + (Contributed by XXX; :issue:`1674032`.) + * The :mod:`unittest` module was enhanced in several ways. - The progress messages will now print 'x' for expected failures - and 'u' for unexpected successes when run in its verbose mode. + The progress messages will now show 'x' for expected failures + and 'u' for unexpected successes when run in verbose mode. (Contributed by Benjamin Peterson.) Test cases can raise the :exc:`SkipTest` exception to skip a test. (:issue:`1034053`.) @@ -443,7 +487,37 @@ changes, or look through the Subversion logs for all the details. importlib: Importing Modules ------------------------------ -XXX write this +Python 3.1 includes the :mod:`importlib` package, a re-implementation +of the logic underlying Python's :keyword:`import` statement. +:mod:`importlib` is useful for implementors of Python interpreters and +to user who wish to write new importers that can participate in the +import process. Python 2.7 doesn't contain the complete +:mod:`importlib` package, but instead has a tiny subset that contains +a single function, :func:`import_module`. + +``import_module(*name*, *package*=None)`` imports a module. *name* is +a string containing the module or package's name. It's possible to do +relative imports by providing a string that begins with a ``.`` +character, such as ``..utils.errors``. For relative imports, the +*package* argument must be provided and is the name of the package that +will be used as the anchor for +the relative import. :func:`import_module` both inserts the imported +module into ``sys.modules`` and returns the module object. + +Here are some examples:: + + >>> from importlib import import_module + >>> anydbm = import_module('anydbm') # Standard absolute import + >>> anydbm + + >>> # Relative import + >>> sysconfig = import_module('..sysconfig', 'distutils.command') + >>> sysconfig + + +:mod:`importlib` was implemented by Brett Cannon and introduced in +Python 3.1. + ttk: Themed Widgets for Tk --------------------------