]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-149173: Fix inverted PYTHON_BASIC_REPL environment check in _pyrepl_available...
authorTan Long <tanloong@foxmail.com>
Fri, 1 May 2026 05:32:57 +0000 (13:32 +0800)
committerGitHub <noreply@github.com>
Fri, 1 May 2026 05:32:57 +0000 (22:32 -0700)
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2026-04-30-14-21-26.gh-issue-149173.KJqZm0.rst [new file with mode: 0644]

index c4bc0020646b0df291c2be486943c36e27e0e219..4dd974b375c2592cfaab5929382ac979b89e0521 100644 (file)
@@ -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:
index c5171f3388c965ca0a20360a8aaa51d53bf248ba..db90019975521ea74c1c234658b2cc5a0f8f76ab 100644 (file)
@@ -4753,6 +4753,16 @@ def bœr():
         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):
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 (file)
index 0000000..019ab76
--- /dev/null
@@ -0,0 +1,2 @@
+Fix inverted :envvar:`PYTHON_BASIC_REPL` environment check in
+``pdb._pyrepl_available``.