summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-03-26 20:16:07 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-03-26 20:16:07 (GMT)
commitd8ad68f34c23645c1a1dfadd63470b3851ba5bea (patch)
tree425fbea238f8f36869c6096b3633239387f718d7
parent9eea9d39c1bf0d01ef5ee00cc0c1bedde9c635a7 (diff)
parent17ace7a07c4fe23afc25383799aa184dbb707f14 (diff)
downloadcpython-d8ad68f34c23645c1a1dfadd63470b3851ba5bea.zip
cpython-d8ad68f34c23645c1a1dfadd63470b3851ba5bea.tar.gz
cpython-d8ad68f34c23645c1a1dfadd63470b3851ba5bea.tar.bz2
Merge
-rw-r--r--Doc/library/argparse.rst21
-rw-r--r--Lib/test/test_subprocess.py1
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS5
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])
diff --git a/Misc/ACKS b/Misc/ACKS
index f2bf3cd..9747ae7 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -354,6 +354,7 @@ Brian Harring
Larry Hastings
Shane Hathaway
Rycharde Hawkes
+Ben Hayden
Jochen Hayek
Christian Heimes
Thomas Heller
diff --git a/Misc/NEWS b/Misc/NEWS
index f5ff837..4638fd7 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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
-----