diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2023-07-06 13:23:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-06 13:23:02 (GMT) |
commit | d0c6ba956fca28785ad4dea6423cd44fd1124cad (patch) | |
tree | 6f9b61a27347455e1446947a6ab0f3ae3c2e6292 /Tools | |
parent | 99b00efd5edfd5b26bf9e2a35cbfc96277fdcbb1 (diff) | |
download | cpython-d0c6ba956fca28785ad4dea6423cd44fd1124cad.zip cpython-d0c6ba956fca28785ad4dea6423cd44fd1124cad.tar.gz cpython-d0c6ba956fca28785ad4dea6423cd44fd1124cad.tar.bz2 |
gh-104683: clinic.py: Don't needlessly reimplement `contextlib.redirect_stdout` (#106478)
clinic.py: Don't needlessly reimplement `contextlib.redirect_stdout`
Diffstat (limited to 'Tools')
-rwxr-xr-x | Tools/clinic/clinic.py | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 7ada7e9..306dca8 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1617,19 +1617,6 @@ class CLanguage(Language): return clinic.get_destination('block').dump() - - -@contextlib.contextmanager -def OverrideStdioWith(stdout): - saved_stdout = sys.stdout - sys.stdout = stdout - try: - yield - finally: - assert sys.stdout is stdout - sys.stdout = saved_stdout - - def create_regex( before: str, after: str, @@ -2331,17 +2318,14 @@ def compute_checksum( return s - - class PythonParser: def __init__(self, clinic: Clinic) -> None: pass def parse(self, block: Block) -> None: - s = io.StringIO() - with OverrideStdioWith(s): + with contextlib.redirect_stdout(io.StringIO()) as s: exec(block.input) - block.output = s.getvalue() + block.output = s.getvalue() class Module: |