mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
gh-101640: Make argparse _print_message catch any write error (#101802)
* In particular, don't exit when trying to print to stderr = None. * Add tests Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
parent
92d8bfffbf
commit
42f54d1f92
3 changed files with 37 additions and 3 deletions
|
@ -2605,9 +2605,11 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||
|
||||
def _print_message(self, message, file=None):
|
||||
if message:
|
||||
if file is None:
|
||||
file = _sys.stderr
|
||||
file.write(message)
|
||||
file = file or _sys.stderr
|
||||
try:
|
||||
file.write(message)
|
||||
except (AttributeError, OSError):
|
||||
pass
|
||||
|
||||
# ===============
|
||||
# Exiting methods
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue