Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0c6ba9

Browse files
authored
gh-104683: clinic.py: Don't needlessly reimplement contextlib.redirect_stdout (#106478)
clinic.py: Don't needlessly reimplement `contextlib.redirect_stdout`
1 parent 99b00ef commit d0c6ba9

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

Tools/clinic/clinic.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,19 +1617,6 @@ def render_function(
16171617
return clinic.get_destination('block').dump()
16181618

16191619

1620-
1621-
1622-
@contextlib.contextmanager
1623-
def OverrideStdioWith(stdout):
1624-
saved_stdout = sys.stdout
1625-
sys.stdout = stdout
1626-
try:
1627-
yield
1628-
finally:
1629-
assert sys.stdout is stdout
1630-
sys.stdout = saved_stdout
1631-
1632-
16331620
def create_regex(
16341621
before: str,
16351622
after: str,
@@ -2331,17 +2318,14 @@ def compute_checksum(
23312318
return s
23322319

23332320

2334-
2335-
23362321
class PythonParser:
23372322
def __init__(self, clinic: Clinic) -> None:
23382323
pass
23392324

23402325
def parse(self, block: Block) -> None:
2341-
s = io.StringIO()
2342-
with OverrideStdioWith(s):
2326+
with contextlib.redirect_stdout(io.StringIO()) as s:
23432327
exec(block.input)
2344-
block.output = s.getvalue()
2328+
block.output = s.getvalue()
23452329

23462330

23472331
class Module:

0 commit comments

Comments
 (0)