summaryrefslogtreecommitdiffstats
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorOleg Iarygin <oleg@arhadthedev.net>2023-05-06 22:53:48 (GMT)
committerGitHub <noreply@github.com>2023-05-06 22:53:48 (GMT)
commit42f54d1f9244784fec99e0610aa05a5051e594bb (patch)
tree9261147628e5c1543fc8d3784e34ad4dd5edaa58 /Lib/argparse.py
parent92d8bfffbf377e91d8b92666525cb8700bb1d5e8 (diff)
downloadcpython-42f54d1f9244784fec99e0610aa05a5051e594bb.zip
cpython-42f54d1f9244784fec99e0610aa05a5051e594bb.tar.gz
cpython-42f54d1f9244784fec99e0610aa05a5051e594bb.tar.bz2
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>
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index a819d26..68089a5 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -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