Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support __init__.pyw in imported packages.
  • Loading branch information
serhiy-storchaka committed Oct 30, 2025
commit bc60e6050a9f1efc6ca2611b2e0be8eec2ad91ce
7 changes: 4 additions & 3 deletions Lib/_py_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,12 @@ def _match_filename(pattern, filename, *, MS_WINDOWS=(sys.platform == 'win32')):
if pattern.match(filename): # for backward compatibility
return True
if MS_WINDOWS:
if not is_py and filename[-4:].lower() == '.pyw':
filename = filename[:-4]
is_py = True
if is_py and filename[-9:].lower() in (r'\__init__', '/__init__'):
filename = filename[:-9]
elif not is_py and filename[-4:].lower() == '.pyw':
filename = filename[:-4]
filename = filename.replace('\\', '.')
filename = filename.replace('\\', '/')
else:
if is_py and filename.endswith('/__init__'):
filename = filename[:-9]
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_run_module_bug1764407(self):
p.stdin.write(b'Timer\n')
p.stdin.write(b'exit()\n')
data = kill_python(p)
self.assertIn(b'1 loop', data)
self.assertTrue(data.find(b'1 loop') != -1)
self.assertTrue(data.find(b'__main__.Timer') != -1)

def test_relativedir_bug46421(self):
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_warnings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ def test_filter_module(self):
self.assertEqual(len(w), 6)
self.module.warn_explicit('msg', UserWarning, r'C:\path\to\package\module.PYW', 42)
self.assertEqual(len(w), 7)
self.module.warn_explicit('msg', UserWarning, r'C:\path\to\package\module\__INIT__.PYW', 42)
self.assertEqual(len(w), 8)

with self.module.catch_warnings(record=True) as w:
self.module.simplefilter('error')
Expand Down