https://github.com/python/cpython/commit/5708818a0e8c0a9e02ad667ec9ddb53418ea5117
commit: 5708818a0e8c0a9e02ad667ec9ddb53418ea5117
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: terryjreedy <[email protected]>
date: 2026-07-01T17:33:30Z
summary:

[3.14] gh-80504: Always show the full search path in IDLE Find in Files 
(GH-152740) (#152811)

gh-80504: Always show the full search path in IDLE Find in Files (GH-152740)

The "In files:" field of the Find in Files dialog now always contains a
full directory path, so the grep output shows which directory was searched.
(cherry picked from commit f21f338f1f88352d50362271a7f38c01745a65da)

Co-authored-by: Serhiy Storchaka <[email protected]>

files:
A Misc/NEWS.d/next/IDLE/2026-07-01-16-00-00.gh-issue-80504.gReP.rst
M Lib/idlelib/grep.py
M Lib/idlelib/idle_test/test_grep.py

diff --git a/Lib/idlelib/grep.py b/Lib/idlelib/grep.py
index 42048ff2395fe1..5d604faec23f32 100644
--- a/Lib/idlelib/grep.py
+++ b/Lib/idlelib/grep.py
@@ -40,6 +40,20 @@ def grep(text, io=None, flist=None):
     dialog.open(text, searchphrase, io)
 
 
+def default_glob(path):
+    """Return the initial "In files:" pattern for a file path (gh-80504).
+
+    Always include a full directory so that grep output shows which
+    directory was searched.
+    """
+    dir, base = os.path.split(path)
+    dir = os.path.abspath(dir)  # An empty dir becomes the current directory.
+    head, tail = os.path.splitext(base)
+    if not tail:
+        tail = ".py"
+    return os.path.join(dir, "*" + tail)
+
+
 def walk_error(msg):
     "Handle os.walk error."
     print(msg)
@@ -103,11 +117,7 @@ def open(self, text, searchphrase, io=None):
             path = io.filename or ""
         else:
             path = ""
-        dir, base = os.path.split(path)
-        head, tail = os.path.splitext(base)
-        if not tail:
-            tail = ".py"
-        self.globvar.set(os.path.join(dir, "*" + tail))
+        self.globvar.set(default_glob(path))
 
     def create_entries(self):
         "Create base entry widgets and add widget for search path."
diff --git a/Lib/idlelib/idle_test/test_grep.py 
b/Lib/idlelib/idle_test/test_grep.py
index d67dba76911fcf..94f217effb656e 100644
--- a/Lib/idlelib/idle_test/test_grep.py
+++ b/Lib/idlelib/idle_test/test_grep.py
@@ -37,6 +37,25 @@ def close(self):  # gui method
 _grep = Dummy_grep()
 
 
+class DefaultGlobTest(unittest.TestCase):
+
+    def test_no_path(self):
+        # gh-80504: an unsaved editor or the Shell has no path, so the
+        # pattern uses the current directory, not just '*.py'.
+        self.assertEqual(grep.default_glob(''),
+                         os.path.join(os.getcwd(), '*.py'))
+
+    def test_full_path(self):
+        path = os.path.join(os.path.abspath(os.sep), 'ab', 'foo.py')
+        self.assertEqual(grep.default_glob(path),
+                         os.path.join(os.path.dirname(path), '*.py'))
+
+    def test_other_extension(self):
+        path = os.path.join(os.path.abspath(os.sep), 'ab', 'foo.txt')
+        self.assertEqual(grep.default_glob(path),
+                         os.path.join(os.path.dirname(path), '*.txt'))
+
+
 class FindfilesTest(unittest.TestCase):
 
     @classmethod
diff --git a/Misc/NEWS.d/next/IDLE/2026-07-01-16-00-00.gh-issue-80504.gReP.rst 
b/Misc/NEWS.d/next/IDLE/2026-07-01-16-00-00.gh-issue-80504.gReP.rst
new file mode 100644
index 00000000000000..93adb33202a41c
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2026-07-01-16-00-00.gh-issue-80504.gReP.rst
@@ -0,0 +1,3 @@
+The "In files:" field of IDLE's Find in Files dialog now always contains a
+full directory path, even for an unsaved editor or the Shell.  This shows
+in the grep output which directory was searched.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to