gh-138122: Implement PEP 799 (#138142)

This commit is contained in:
Pablo Galindo Salgado 2025-08-27 17:52:50 +01:00 committed by GitHub
parent f733e428f8
commit 56eb6b64a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 497 additions and 386 deletions

View file

@ -0,0 +1,32 @@
class _Utils:
"""Support class for utility functions which are shared by
profile.py and cProfile.py modules.
Not supposed to be used directly.
"""
def __init__(self, profiler):
self.profiler = profiler
def run(self, statement, filename, sort):
prof = self.profiler()
try:
prof.run(statement)
except SystemExit:
pass
finally:
self._show(prof, filename, sort)
def runctx(self, statement, globals, locals, filename, sort):
prof = self.profiler()
try:
prof.runctx(statement, globals, locals)
except SystemExit:
pass
finally:
self._show(prof, filename, sort)
def _show(self, prof, filename, sort):
if filename is not None:
prof.dump_stats(filename)
else:
prof.print_stats(sort)