@@ -88,6 +88,23 @@ Other Language Changes
8888
8989Some smaller changes made to the core Python language are:
9090
91+ * The string :method: `format ` method now supports automatic numbering
92+ of the replacement fields. This makes using :meth: `format `
93+ more closely resemble using ``%s `` formatting::
94+
95+ >>> '{}:{}:{}'.format(2009, 04, 'Sunday')
96+ '2009:4:Sunday'
97+ >>> '{}:{}:{day}'.format(2009, 4, day='Sunday')
98+ '2009:4:Sunday'
99+
100+ The auto-numbering takes the fields from left to right, so the first
101+ ``{...} `` specifier will use the first argument to :meth: `format `,
102+ the next specifier will use the next argument, and so on. You can't
103+ mix auto-numbering and explicit numbering -- either number all of
104+ your specifier fields or none of them -- but you can mix
105+ auto-numbering and named fields, as in the second example above.
106+ (Contributed by XXX; :issue`5237`.)
107+
91108* The :func: `int ` and :func: `long ` types gained a ``bit_length ``
92109 method that returns the number of bits necessary to represent
93110 its argument in binary::
@@ -106,7 +123,7 @@ Some smaller changes made to the core Python language are:
106123 (Contributed by Fredrik Johansson and Victor Stinner; :issue: `3439 `.)
107124
108125* The :class: `bytearray ` type's :meth: `translate ` method will
109- now accept None as its first argument. (Fixed by Georg Brandl;
126+ now accept `` None `` as its first argument. (Fixed by Georg Brandl;
110127 :issue: `4759 `.)
111128
112129.. ======================================================================
@@ -201,7 +218,7 @@ changes, or look through the Subversion logs for all the details.
201218 management protocol, so you can write ``with bz2.BZ2File(...) as f: ... ``.
202219 (Contributed by Hagen Fuerstenau; :issue: `3860 `.)
203220
204- * A new :class: `Counter ` class in the :mod: `collections ` module is
221+ * New class: the :class: `Counter ` class in the :mod: `collections ` module is
205222 useful for tallying data. :class: `Counter ` instances behave mostly
206223 like dictionaries but return zero for missing keys instead of
207224 raising a :exc: `KeyError `::
@@ -236,7 +253,7 @@ changes, or look through the Subversion logs for all the details.
236253 Contributed by Raymond Hettinger; :issue: `1696199 `.
237254
238255 The :class: `namedtuple ` class now has an optional *rename * parameter.
239- If *rename * is True , field names that are invalid because they've
256+ If *rename * is true , field names that are invalid because they've
240257 been repeated or that aren't legal Python identifiers will be
241258 renamed to legal names that are derived from the field's
242259 position within the list of fields:
@@ -247,15 +264,26 @@ changes, or look through the Subversion logs for all the details.
247264
248265 (Added by Raymond Hettinger; :issue: `1818 `.)
249266
267+ The :class: `deque ` data type now exposes its maximum length as the
268+ read-only :attr: `maxlen ` attribute. (Added by Raymond Hettinger.)
269+
250270* In Distutils, :func: `distutils.sdist.add_defaults ` now uses
251271 *package_dir * and *data_files * to create the MANIFEST file.
272+ :mod: `distutils.sysconfig ` will now read the :envvar: `AR `
273+ environment variable.
252274
253275 It is no longer mandatory to store clear-text passwords in the
254276 :file: `.pypirc ` file when registering and uploading packages to PyPI. As long
255277 as the username is present in that file, the :mod: `distutils ` package will
256278 prompt for the password if not present. (Added by Tarek Ziade,
257279 based on an initial contribution by Nathan Van Gheem; :issue: `4394 `.)
258280
281+ A Distutils setup can now specify that a C extension is optional by
282+ setting the *optional * option setting to true. If this optional is
283+ supplied, failure to build the extension will not abort the build
284+ process, but instead simply not install the failing extension.
285+ (Contributed by Georg Brandl; :issue: `5583 `.)
286+
259287* New method: the :class: `Decimal ` class gained a
260288 :meth: `from_float ` class method that performs an exact conversion
261289 of a floating-point number to a :class: `Decimal `.
@@ -267,8 +295,8 @@ changes, or look through the Subversion logs for all the details.
267295 ``Decimal('0.1000000000000000055511151231257827021181583404541015625') ``.
268296 (Implemented by Raymond Hettinger; :issue: `4796 `.)
269297
270- * A new function in the :mod: `gc ` module, :func: `is_tracked `, returns
271- True if a given instance is tracked by the garbage collector, False
298+ * New function: the :mod: `gc ` module's :func: `is_tracked ` returns
299+ true if a given instance is tracked by the garbage collector, false
272300 otherwise. (Contributed by Antoine Pitrou; :issue: `4688 `.)
273301
274302* 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.
284312
285313* New function: ``itertools.compress(*data*, *selectors*) `` takes two
286314 iterators. Elements of *data * are returned if the corresponding
287- value in *selectors * is True ::
315+ value in *selectors * is true ::
288316
289317 itertools.compress('ABCDEF', [1,0,1,0,1,1]) =>
290318 A, C, E, F
@@ -322,12 +350,22 @@ changes, or look through the Subversion logs for all the details.
322350 with any object literal that decodes to a list of pairs.
323351 (Contributed by Raymond Hettinger; :issue: `5381 `.)
324352
353+ * The :mod: `multiprocessing ` module's :class: `Manager* ` classes
354+ can now be passed a callable that will be called whenever
355+ a subprocess is started, along with a set of arguments that will be
356+ passed to the callable.
357+ (Contributed by lekma; :issue: `5585 `.)
358+
325359* The :mod: `pydoc ` module now has help for the various symbols that Python
326360 uses. You can now do ``help('<<') `` or ``help('@') ``, for example.
327361 (Contributed by David Laban; :issue: `4739 `.)
328362
329- * A new function in the :mod: `subprocess ` module,
330- :func: `check_output `, runs a command with a specified set of arguments
363+ * The :mod: `re ` module's :func: `split `, :func: `sub `, and :func: `subn `
364+ now accept an optional *flags * argument, for consistency with the
365+ other functions in the module. (Added by Gregory P. Smith.)
366+
367+ * New function: the :mod: `subprocess ` module's
368+ :func: `check_output ` runs a command with a specified set of arguments
331369 and returns the command's output as a string when the command runs without
332370 error, or raises a :exc: `CalledProcessError ` exception otherwise.
333371
@@ -343,26 +381,99 @@ changes, or look through the Subversion logs for all the details.
343381
344382 (Contributed by Gregory P. Smith.)
345383
384+ * New function: :func: `is_declared_global ` in the :mod: `symtable ` module
385+ returns true for variables that are explicitly declared to be global,
386+ false for ones that are implicitly global.
387+ (Contributed by Jeremy Hylton.)
388+
346389* The ``sys.version_info `` value is now a named tuple, with attributes
347390 named ``major ``, ``minor ``, ``micro ``, ``releaselevel ``, and ``serial ``.
348391 (Contributed by Ross Light; :issue: `4285 `.)
349392
393+ * The :mod: `threading ` module's :meth: `Event.wait ` method now returns
394+ the internal flag on exit. This means the method will usually
395+ return true because :meth: `wait ` is supposed to block until the
396+ internal flag becomes true. The return value will only be false if
397+ a timeout was provided and the operation timed out.
398+ (Contributed by XXX; :issue: `1674032 `.)
399+
350400* The :mod: `unittest ` module was enhanced in several ways.
401+ The progress messages will now show 'x' for expected failures
402+ and 'u' for unexpected successes when run in verbose mode.
403+ (Contributed by Benjamin Peterson.)
351404 Test cases can raise the :exc: `SkipTest ` exception to skip a test.
352405 (:issue: `1034053 `.)
353- It will now use 'x' for expected failures
354- and 'u' for unexpected successes when run in its verbose mode.
355- (Contributed by Benjamin Peterson.)
406+
407+ The error messages for :meth: `assertEqual `,
408+ :meth: `assertTrue `, and :meth: `assertFalse `
409+ failures now provide more information. If you set the
410+ :attr: `longMessage ` attribute of your :class: `TestCase ` classes to
411+ true, both the standard error message and any additional message you
412+ provide will be printed for failures. (Added by Michael Foord; :issue: `5663 `.)
356413
357414 The :meth: `assertRaises ` and :meth: `failUnlessRaises ` methods now
358415 return a context handler when called without providing a callable
359416 object to run. For example, you can write this::
360417
361- with self.assertRaises(KeyError):
362- raise ValueError
418+ with self.assertRaises(KeyError):
419+ raise ValueError
363420
364421 (Implemented by Antoine Pitrou; :issue: `4444 `.)
365422
423+ A number of new methods were added that provide more specialized
424+ tests. Many of these methods were written by Google engineers
425+ for use in their test suites; Gregory P. Smith, Michael Foord, and
426+ GvR worked on merging them into Python's version of :mod: `unittest `.
427+
428+ * :meth: `assertIsNone ` and :meth: `assertIsNotNone ` take one
429+ expression and verify that the result is or is not ``None ``.
430+
431+ * :meth: `assertIs ` and :meth: `assertIsNot ` take two values and check
432+ whether the two values evaluate to the same object or not.
433+ (Added by Michael Foord; :issue: `2578 `.)
434+
435+ * :meth: `assertGreater `, :meth: `assertGreaterEqual `,
436+ :meth: `assertLess `, and :meth: `assertLessEqual ` compare
437+ two quantities.
438+
439+ * :meth: `assertMultiLineEqual ` compares two strings, and if they're
440+ not equal, displays a helpful comparison that highlights the
441+ differences in the two strings.
442+
443+ * :meth: `assertRegexpMatches ` checks whether its first argument is a
444+ string matching a regular expression provided as its second argument.
445+
446+ * :meth: `assertRaisesRegexp ` checks whether a particular exception
447+ is raised, and then also checks that the string representation of
448+ the exception matches the provided regular expression.
449+
450+ * :meth: `assertIn ` and :meth: `assertNotIn ` tests whether
451+ *first * is or is not in *second *.
452+
453+ * :meth: `assertSameElements ` tests whether two provided sequences
454+ contain the same elements.
455+
456+ * :meth: `assertSetEqual ` compares whether two sets are equal, and
457+ only reports the differences between the sets in case of error.
458+
459+ * Similarly, :meth: `assertListEqual ` and :meth: `assertTupleEqual `
460+ compare the specified types and explain the differences.
461+ More generally, :meth: `assertSequenceEqual ` compares two sequences
462+ and can optionally check whether both sequences are of a
463+ particular type.
464+
465+ * :meth: `assertDictEqual ` compares two dictionaries and reports the
466+ differences. :meth: `assertDictContainsSubset ` checks whether
467+ all of the key/value pairs in *first * are found in *second *.
468+
469+ * A new hook, :meth: `addTypeEqualityFunc ` takes a type object and a
470+ function. The :meth: `assertEqual ` method will use the function
471+ when both of the objects being compared are of the specified type.
472+ This function should compare the two objects and raise an
473+ exception if they don't match; it's a good idea for the function
474+ to provide additional information about why the two objects are
475+ matching, much as the new sequence comparison methods do.
476+
366477* The :func: `is_zipfile ` function in the :mod: `zipfile ` module will now
367478 accept a file object, in addition to the path names accepted in earlier
368479 versions. (Contributed by Gabriel Genellina; :issue: `4756 `.)
@@ -376,7 +487,37 @@ changes, or look through the Subversion logs for all the details.
376487 importlib: Importing Modules
377488------------------------------
378489
379- XXX write this
490+ Python 3.1 includes the :mod: `importlib ` package, a re-implementation
491+ of the logic underlying Python's :keyword: `import ` statement.
492+ :mod: `importlib ` is useful for implementors of Python interpreters and
493+ to user who wish to write new importers that can participate in the
494+ import process. Python 2.7 doesn't contain the complete
495+ :mod: `importlib ` package, but instead has a tiny subset that contains
496+ a single function, :func: `import_module `.
497+
498+ ``import_module(*name*, *package*=None) `` imports a module. *name * is
499+ a string containing the module or package's name. It's possible to do
500+ relative imports by providing a string that begins with a ``. ``
501+ character, such as ``..utils.errors ``. For relative imports, the
502+ *package * argument must be provided and is the name of the package that
503+ will be used as the anchor for
504+ the relative import. :func: `import_module ` both inserts the imported
505+ module into ``sys.modules `` and returns the module object.
506+
507+ Here are some examples::
508+
509+ >>> from importlib import import_module
510+ >>> anydbm = import_module('anydbm') # Standard absolute import
511+ >>> anydbm
512+ <module 'anydbm' from '/p/python/Lib/anydbm.py'>
513+ >>> # Relative import
514+ >>> sysconfig = import_module('..sysconfig', 'distutils.command')
515+ >>> sysconfig
516+ <module 'distutils.sysconfig' from '/p/python/Lib/distutils/sysconfig.pyc'>
517+
518+ :mod: `importlib ` was implemented by Brett Cannon and introduced in
519+ Python 3.1.
520+
380521
381522ttk: Themed Widgets for Tk
382523--------------------------
0 commit comments