gh-104683: clinic.py: Don't needlessly reimplement contextlib.redirect_stdout (#106478)

clinic.py: Don't needlessly reimplement `contextlib.redirect_stdout`
This commit is contained in:
Alex Waygood 2023-07-06 14:23:02 +01:00 committed by GitHub
parent 99b00efd5e
commit d0c6ba956f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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: