Skip to content

Commit

Permalink
gh-104683: clinic.py: Don't needlessly reimplement `contextlib.redire…
Browse files Browse the repository at this point in the history
…ct_stdout` (#106478)

clinic.py: Don't needlessly reimplement `contextlib.redirect_stdout`
  • Loading branch information
AlexWaygood authored Jul 6, 2023
1 parent 99b00ef commit d0c6ba9
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,19 +1617,6 @@ def render_function(
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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d0c6ba9

Please sign in to comment.