This commit is contained in:
Antoine Pitrou 2011-03-26 21:16:07 +01:00
commit d8ad68f34c
4 changed files with 23 additions and 5 deletions

View File

@ -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]) 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 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 already existing object, rather than a new :class:`Namespace` object. This can
that is normally used. This can be achieved by specifying the ``namespace=`` be achieved by specifying the ``namespace=`` keyword argument::
keyword argument::
>>> class C: >>> class C:
... pass ... pass

View File

@ -1226,6 +1226,7 @@ class POSIXProcessTestCase(BaseTestCase):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
bufsize=0) bufsize=0)
f = p.stdout f = p.stdout
self.addCleanup(f.close)
try: try:
self.assertEqual(f.read(4), b"appl") self.assertEqual(f.read(4), b"appl")
self.assertIn(f, select.select([f], [], [], 0.0)[0]) self.assertIn(f, select.select([f], [], [], 0.0)[0])

View File

@ -354,6 +354,7 @@ Brian Harring
Larry Hastings Larry Hastings
Shane Hathaway Shane Hathaway
Rycharde Hawkes Rycharde Hawkes
Ben Hayden
Jochen Hayek Jochen Hayek
Christian Heimes Christian Heimes
Thomas Heller Thomas Heller

View File

@ -53,6 +53,9 @@ Core and Builtins
Library 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 - Issue #11635: Don't use polling in worker threads and processes launched by
concurrent.futures. concurrent.futures.
@ -157,6 +160,8 @@ Library
- Issue #9348: Raise an early error if argparse nargs and metavar don't match. - 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 Build
----- -----