Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc31547a

Browse files
Eclips4ambv
andauthored
gh-134097: Print number of refs & blocks after each statement in new REPL (gh-134136)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
1 parent44b73d3 commitc31547a

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

‎Lib/_pyrepl/simple_interact.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ def run_multiline_interactive_console(
110110
more_lines=functools.partial(_more_lines,console)
111111
input_n=0
112112

113+
_is_x_showrefcount_set=sys._xoptions.get("showrefcount")
114+
_is_pydebug_build=hasattr(sys,"gettotalrefcount")
115+
show_ref_count=_is_x_showrefcount_setand_is_pydebug_build
116+
113117
defmaybe_run_command(statement:str)->bool:
114118
statement=statement.strip()
115119
ifstatementinconsole.localsorstatementnotinREPL_COMMANDS:
@@ -167,3 +171,8 @@ def maybe_run_command(statement: str) -> bool:
167171
except:
168172
console.showtraceback()
169173
console.resetbuffer()
174+
ifshow_ref_count:
175+
console.write(
176+
f"[{sys.gettotalrefcount()} refs,"
177+
f"{sys.getallocatedblocks()} blocks]\n"
178+
)

‎Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
importtempfile
1111
fromunittestimportTestCase,skipUnless,skipIf
1212
fromunittest.mockimportpatch
13-
fromtest.supportimportforce_not_colorized,make_clean_env
13+
fromtest.supportimportforce_not_colorized,make_clean_env,Py_DEBUG
1414
fromtest.supportimportSHORT_TIMEOUT,STDLIB_DIR
1515
fromtest.support.import_helperimportimport_module
1616
fromtest.support.os_helperimportEnvironmentVarGuard,unlink
@@ -1610,3 +1610,16 @@ def test_prompt_after_help(self):
16101610
# Extra stuff (newline and `exit` rewrites) are necessary
16111611
# because of how run_repl works.
16121612
self.assertNotIn(">>>\n>>> >>>",cleaned_output)
1613+
1614+
@skipUnless(Py_DEBUG,'-X showrefcount requires a Python debug build')
1615+
deftest_showrefcount(self):
1616+
env=os.environ.copy()
1617+
env.pop("PYTHON_BASIC_REPL","")
1618+
output,_=self.run_repl("1\n1+2\nexit()\n",cmdline_args=['-Xshowrefcount'],env=env)
1619+
matches=re.findall(r'\[-?\d+ refs, \d+ blocks\]',output)
1620+
self.assertEqual(len(matches),3)
1621+
1622+
env["PYTHON_BASIC_REPL"]="1"
1623+
output,_=self.run_repl("1\n1+2\nexit()\n",cmdline_args=['-Xshowrefcount'],env=env)
1624+
matches=re.findall(r'\[-?\d+ refs, \d+ blocks\]',output)
1625+
self.assertEqual(len(matches),3)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix interaction of the new:term:`REPL` and:option:`-X showrefcount <-X>` command line option.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp