diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-03-26 20:16:07 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-03-26 20:16:07 (GMT) |
commit | d8ad68f34c23645c1a1dfadd63470b3851ba5bea (patch) | |
tree | 425fbea238f8f36869c6096b3633239387f718d7 | |
parent | 9eea9d39c1bf0d01ef5ee00cc0c1bedde9c635a7 (diff) | |
parent | 17ace7a07c4fe23afc25383799aa184dbb707f14 (diff) | |
download | cpython-d8ad68f34c23645c1a1dfadd63470b3851ba5bea.zip cpython-d8ad68f34c23645c1a1dfadd63470b3851ba5bea.tar.gz cpython-d8ad68f34c23645c1a1dfadd63470b3851ba5bea.tar.bz2 |
Merge
-rw-r--r-- | Doc/library/argparse.rst | 21 | ||||
-rw-r--r-- | Lib/test/test_subprocess.py | 1 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 5 |
4 files changed, 23 insertions, 5 deletions
diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 8bd3ca5..102b3e9 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1314,13 +1314,24 @@ of :data:`sys.argv`. This can be accomplished by passing a list of strings to Namespace(accumulate=<built-in function sum>, integers=[1, 2, 3, 4]) -Custom namespaces -^^^^^^^^^^^^^^^^^ +The Namespace object +^^^^^^^^^^^^^^^^^^^^ + +By default, :meth:`parse_args` will return a new object of type :class:`Namespace` +where the necessary attributes have been set. This class is deliberately simple, +just an :class:`object` subclass with a readable string representation. If you +prefer to have dict-like view of the attributes, you can use the standard Python +idiom via :func:`vars`:: + + >>> parser = argparse.ArgumentParser() + >>> parser.add_argument('--foo') + >>> args = parser.parse_args(['--foo', 'BAR']) + >>> vars(args) + {'foo': 'BAR'} It may also be useful to have an :class:`ArgumentParser` assign attributes to an -already existing object, rather than the newly-created :class:`Namespace` object -that is normally used. This can be achieved by specifying the ``namespace=`` -keyword argument:: +already existing object, rather than a new :class:`Namespace` object. This can +be achieved by specifying the ``namespace=`` keyword argument:: >>> class C: ... pass diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 01e670e..7ca3d92 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1226,6 +1226,7 @@ class POSIXProcessTestCase(BaseTestCase): stdout=subprocess.PIPE, bufsize=0) f = p.stdout + self.addCleanup(f.close) try: self.assertEqual(f.read(4), b"appl") self.assertIn(f, select.select([f], [], [], 0.0)[0]) @@ -354,6 +354,7 @@ Brian Harring Larry Hastings Shane Hathaway Rycharde Hawkes +Ben Hayden Jochen Hayek Christian Heimes Thomas Heller @@ -53,6 +53,9 @@ Core and Builtins Library ------- +- Issue #11659: Fix ResourceWarning in test_subprocess introduced by #11459. + Patch by Ben Hayden. + - Issue #11635: Don't use polling in worker threads and processes launched by concurrent.futures. @@ -157,6 +160,8 @@ Library - Issue #9348: Raise an early error if argparse nargs and metavar don't match. +- Issue #8982: Improve the documentation for the argparse Namespace object. + Build ----- |