From f98ee984ec55dc3e16cbdfa7e72516fedeb91780 Mon Sep 17 00:00:00 2001 From: Tan Long Date: Thu, 30 Apr 2026 14:14:31 +0800 Subject: [PATCH 1/5] Fix inverted PYTHON_BASIC_REPL environment check in _pyrepl_available() --- Lib/pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index c4bc0020646b0d..4dd974b375c259 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -376,7 +376,7 @@ def get_default_backend(): def _pyrepl_available(): """return whether pdb should use _pyrepl for input""" - if not os.getenv("PYTHON_BASIC_REPL"): + if os.getenv("PYTHON_BASIC_REPL"): CAN_USE_PYREPL = False else: try: From eba912ec86af6469e4ebe4405359b3e92c0624dc Mon Sep 17 00:00:00 2001 From: Tan Long Date: Thu, 30 Apr 2026 14:21:32 +0800 Subject: [PATCH 2/5] blurb --- .../next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst diff --git a/Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst b/Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst new file mode 100644 index 00000000000000..6e71caa339a788 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst @@ -0,0 +1,2 @@ +Fix inverted :envvar:`PYTHON_BASIC_REPL` environment check in +:func:`pdb._pyrepl_available()`. From 3a56ed57aabc3058883d22bb879cbba3528881fd Mon Sep 17 00:00:00 2001 From: Tan Long Date: Thu, 30 Apr 2026 14:23:48 +0800 Subject: [PATCH 3/5] fix sphinx-lint error --- .../next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst b/Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst index 6e71caa339a788..045ef25897c104 100644 --- a/Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst +++ b/Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst @@ -1,2 +1,2 @@ Fix inverted :envvar:`PYTHON_BASIC_REPL` environment check in -:func:`pdb._pyrepl_available()`. +:func:`pdb._pyrepl_available`. From f6efdf6a4b67194f34444641936984ffd1330025 Mon Sep 17 00:00:00 2001 From: Tan Long Date: Thu, 30 Apr 2026 14:32:27 +0800 Subject: [PATCH 4/5] fix py:func reference target not found --- .../next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst b/Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst index 045ef25897c104..019ab76b863577 100644 --- a/Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst +++ b/Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst @@ -1,2 +1,2 @@ Fix inverted :envvar:`PYTHON_BASIC_REPL` environment check in -:func:`pdb._pyrepl_available`. +``pdb._pyrepl_available``. From b25ddf56ff766b058219a49a7308746ffa4dd4d8 Mon Sep 17 00:00:00 2001 From: Tan Long Date: Thu, 30 Apr 2026 14:51:55 +0800 Subject: [PATCH 5/5] add test --- Lib/test/test_pdb.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index c5171f3388c965..db90019975521e 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4753,6 +4753,16 @@ def foo(self): stdout, stderr = self.run_pdb_script(script, commands) self.assertIn("The specified object 'C.foo' is not a function", stdout) + def test_pyrepl_available(self): + with patch.dict(os.environ, {"PYTHON_BASIC_REPL": "1"}): + self.assertFalse(pdb._pyrepl_available()) + + with patch.dict(os.environ, {}, clear=True): + mod = types.ModuleType("_pyrepl.main") + mod.CAN_USE_PYREPL = True + with patch.dict("sys.modules", {"_pyrepl.main": mod}): + self.assertTrue(pdb._pyrepl_available()) + class ChecklineTests(unittest.TestCase): def setUp(self):