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

Commit08c9ba5

Browse files
miss-islingtonEclips4ambv
authored
[3.13]gh-134097: Print number of refs & blocks after each statement in new REPL (gh-134136) (gh-134221)
(cherry picked from commitc31547a)Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>Co-authored-by: Łukasz Langa <lukasz@langa.pl>
1 parent55a7cb1 commit08c9ba5

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
@@ -114,6 +114,10 @@ def run_multiline_interactive_console(
114114
more_lines=functools.partial(_more_lines,console)
115115
input_n=0
116116

117+
_is_x_showrefcount_set=sys._xoptions.get("showrefcount")
118+
_is_pydebug_build=hasattr(sys,"gettotalrefcount")
119+
show_ref_count=_is_x_showrefcount_setand_is_pydebug_build
120+
117121
defmaybe_run_command(statement:str)->bool:
118122
statement=statement.strip()
119123
ifstatementinconsole.localsorstatementnotinREPL_COMMANDS:
@@ -168,3 +172,8 @@ def maybe_run_command(statement: str) -> bool:
168172
except:
169173
console.showtraceback()
170174
console.resetbuffer()
175+
ifshow_ref_count:
176+
console.write(
177+
f"[{sys.gettotalrefcount()} refs,"
178+
f"{sys.getallocatedblocks()} blocks]\n"
179+
)

‎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
@@ -1380,3 +1380,16 @@ def test_prompt_after_help(self):
13801380
# Extra stuff (newline and `exit` rewrites) are necessary
13811381
# because of how run_repl works.
13821382
self.assertNotIn(">>>\n>>> >>>",cleaned_output)
1383+
1384+
@skipUnless(Py_DEBUG,'-X showrefcount requires a Python debug build')
1385+
deftest_showrefcount(self):
1386+
env=os.environ.copy()
1387+
env.pop("PYTHON_BASIC_REPL","")
1388+
output,_=self.run_repl("1\n1+2\nexit()\n",cmdline_args=['-Xshowrefcount'],env=env)
1389+
matches=re.findall(r'\[-?\d+ refs, \d+ blocks\]',output)
1390+
self.assertEqual(len(matches),3)
1391+
1392+
env["PYTHON_BASIC_REPL"]="1"
1393+
output,_=self.run_repl("1\n1+2\nexit()\n",cmdline_args=['-Xshowrefcount'],env=env)
1394+
matches=re.findall(r'\[-?\d+ refs, \d+ blocks\]',output)
1395+
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