Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8ad68f

Browse files
committed
Merge
2 parents 9eea9d3 + 17ace7a commit d8ad68f

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

Doc/library/argparse.rst

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,13 +1314,24 @@ of :data:`sys.argv`. This can be accomplished by passing a list of strings to
13141314
Namespace(accumulate=<built-in function sum>, integers=[1, 2, 3, 4])
13151315

13161316

1317-
Custom namespaces
1318-
^^^^^^^^^^^^^^^^^
1317+
The Namespace object
1318+
^^^^^^^^^^^^^^^^^^^^
1319+
1320+
By default, :meth:`parse_args` will return a new object of type :class:`Namespace`
1321+
where the necessary attributes have been set. This class is deliberately simple,
1322+
just an :class:`object` subclass with a readable string representation. If you
1323+
prefer to have dict-like view of the attributes, you can use the standard Python
1324+
idiom via :func:`vars`::
1325+
1326+
>>> parser = argparse.ArgumentParser()
1327+
>>> parser.add_argument('--foo')
1328+
>>> args = parser.parse_args(['--foo', 'BAR'])
1329+
>>> vars(args)
1330+
{'foo': 'BAR'}
13191331

13201332
It may also be useful to have an :class:`ArgumentParser` assign attributes to an
1321-
already existing object, rather than the newly-created :class:`Namespace` object
1322-
that is normally used. This can be achieved by specifying the ``namespace=``
1323-
keyword argument::
1333+
already existing object, rather than a new :class:`Namespace` object. This can
1334+
be achieved by specifying the ``namespace=`` keyword argument::
13241335

13251336
>>> class C:
13261337
... pass

Lib/test/test_subprocess.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,7 @@ def test_select_unbuffered(self):
12261226
stdout=subprocess.PIPE,
12271227
bufsize=0)
12281228
f = p.stdout
1229+
self.addCleanup(f.close)
12291230
try:
12301231
self.assertEqual(f.read(4), b"appl")
12311232
self.assertIn(f, select.select([f], [], [], 0.0)[0])

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ Brian Harring
354354
Larry Hastings
355355
Shane Hathaway
356356
Rycharde Hawkes
357+
Ben Hayden
357358
Jochen Hayek
358359
Christian Heimes
359360
Thomas Heller

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ Core and Builtins
5353
Library
5454
-------
5555

56+
- Issue #11659: Fix ResourceWarning in test_subprocess introduced by #11459.
57+
Patch by Ben Hayden.
58+
5659
- Issue #11635: Don't use polling in worker threads and processes launched by
5760
concurrent.futures.
5861

@@ -157,6 +160,8 @@ Library
157160

158161
- Issue #9348: Raise an early error if argparse nargs and metavar don't match.
159162

163+
- Issue #8982: Improve the documentation for the argparse Namespace object.
164+
160165
Build
161166
-----
162167

0 commit comments

Comments
 (0)