Skip to content

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Oct 15, 2025

  • Try to match the module name pattern with module names constructed starting from different parent directories of the filename. E.g., for "/path/to/package/module" try to match with "path.to.package.module", "to.package.module", "package.module" and "module".
  • Ignore trailing "/__init__.py".
  • Ignore trailing ".pyw" on Windows.
  • Keep matching with the full filename (without optional ".py" suffix) for compatibility.
  • Only ignore the case of the ".py" extension on Windows.

@serhiy-storchaka
Copy link
Member Author

Since we need the code for Python and C implementations of warn_explicit(), and it is relatively complex, it is only implemented in Python, and the C code imports the Python implementation.

…ut module argument

* Try to match the module name pattern with module names constructed
  starting from different parent directories of the filename.
  E.g., for "/path/to/package/module" try to match with
  "path.to.package.module", "to.package.module", "package.module" and
  "module".
* Ignore trailing "/__init__.py".
* Ignore trailing ".py" on Windows.
* Keep matching with the full filename (without optional ".py" extension)
  for compatibility.
* Only ignore the case of the ".py" extension on Windows.
@serhiy-storchaka
Copy link
Member Author

Ready for review.

@serhiy-storchaka
Copy link
Member Author

This is definitely a new feature, but it would be nice to backport it to 3.14.1, taking into account how much fuss was made by new syntax warnings in 3.14. This would mitigate impact. cc @hugovk

@hugovk
Copy link
Member

hugovk commented Oct 29, 2025

Thank you for working on this.

Before even considering this for 3.14, I'd want to see it in a 3.15 alpha first, with testing and feedback from those unhappy with the 3.14 syntax warnings that this addresses their needs.

Comment on lines 537 to 540
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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\__init__.pyw is supported on Windows, you can do something like:

Suggested change
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]
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]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I was too lazy to check and mistakenly supposed that .pyw is not supported for __init__. But I just checked -- indeed, it works.

filename = support.findfile('test_import/data/syntax_warnings.py')
with open(filename, 'rb') as f:
source = f.read()
with warnings.catch_warnings(record=True) as wlog:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may use a loop since the code is basically duplicated. Something like:

for exec_globals in ...:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of tests (except test_warnings) is actually a ground for other PR. They will not be duplicates in https://github.com/python/cpython/pull/139652/files#diff-f23235c1f5dea0e2d79b33a58e00025ad3c440f96bb76013a1a37868e70a776b

Copy link
Member Author

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review. You noticed 👀 some details that I missed.

Comment on lines 537 to 540
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]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I was too lazy to check and mistakenly supposed that .pyw is not supported for __init__. But I just checked -- indeed, it works.

filename = support.findfile('test_import/data/syntax_warnings.py')
with open(filename, 'rb') as f:
source = f.read()
with warnings.catch_warnings(record=True) as wlog:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of tests (except test_warnings) is actually a ground for other PR. They will not be duplicates in https://github.com/python/cpython/pull/139652/files#diff-f23235c1f5dea0e2d79b33a58e00025ad3c440f96bb76013a1a37868e70a776b

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@serhiy-storchaka serhiy-storchaka merged commit 6826166 into python:main Oct 30, 2025
50 checks passed
@serhiy-storchaka serhiy-storchaka deleted the warn_explicit-no-module branch October 30, 2025 13:55
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot aarch64 Android 3.x (tier-3) has failed when building commit 6826166.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1594/builds/3659) and take a look at the build logs.
  4. Check if the failure is related to this commit (6826166) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1594/builds/3659

Summary of the results of the build (if available):

Click to see traceback logs
remote: Enumerating objects: 55, done.        
remote: Counting objects:   1% (1/55)        
remote: Counting objects:   3% (2/55)        
remote: Counting objects:   5% (3/55)        
remote: Counting objects:   7% (4/55)        
remote: Counting objects:   9% (5/55)        
remote: Counting objects:  10% (6/55)        
remote: Counting objects:  12% (7/55)        
remote: Counting objects:  14% (8/55)        
remote: Counting objects:  16% (9/55)        
remote: Counting objects:  18% (10/55)        
remote: Counting objects:  20% (11/55)        
remote: Counting objects:  21% (12/55)        
remote: Counting objects:  23% (13/55)        
remote: Counting objects:  25% (14/55)        
remote: Counting objects:  27% (15/55)        
remote: Counting objects:  29% (16/55)        
remote: Counting objects:  30% (17/55)        
remote: Counting objects:  32% (18/55)        
remote: Counting objects:  34% (19/55)        
remote: Counting objects:  36% (20/55)        
remote: Counting objects:  38% (21/55)        
remote: Counting objects:  40% (22/55)        
remote: Counting objects:  41% (23/55)        
remote: Counting objects:  43% (24/55)        
remote: Counting objects:  45% (25/55)        
remote: Counting objects:  47% (26/55)        
remote: Counting objects:  49% (27/55)        
remote: Counting objects:  50% (28/55)        
remote: Counting objects:  52% (29/55)        
remote: Counting objects:  54% (30/55)        
remote: Counting objects:  56% (31/55)        
remote: Counting objects:  58% (32/55)        
remote: Counting objects:  60% (33/55)        
remote: Counting objects:  61% (34/55)        
remote: Counting objects:  63% (35/55)        
remote: Counting objects:  65% (36/55)        
remote: Counting objects:  67% (37/55)        
remote: Counting objects:  69% (38/55)        
remote: Counting objects:  70% (39/55)        
remote: Counting objects:  72% (40/55)        
remote: Counting objects:  74% (41/55)        
remote: Counting objects:  76% (42/55)        
remote: Counting objects:  78% (43/55)        
remote: Counting objects:  80% (44/55)        
remote: Counting objects:  81% (45/55)        
remote: Counting objects:  83% (46/55)        
remote: Counting objects:  85% (47/55)        
remote: Counting objects:  87% (48/55)        
remote: Counting objects:  89% (49/55)        
remote: Counting objects:  90% (50/55)        
remote: Counting objects:  92% (51/55)        
remote: Counting objects:  94% (52/55)        
remote: Counting objects:  96% (53/55)        
remote: Counting objects:  98% (54/55)        
remote: Counting objects: 100% (55/55)        
remote: Counting objects: 100% (55/55), done.        
remote: Compressing objects:   5% (1/20)        
remote: Compressing objects:  10% (2/20)        
remote: Compressing objects:  15% (3/20)        
remote: Compressing objects:  20% (4/20)        
remote: Compressing objects:  25% (5/20)        
remote: Compressing objects:  30% (6/20)        
remote: Compressing objects:  35% (7/20)        
remote: Compressing objects:  40% (8/20)        
remote: Compressing objects:  45% (9/20)        
remote: Compressing objects:  50% (10/20)        
remote: Compressing objects:  55% (11/20)        
remote: Compressing objects:  60% (12/20)        
remote: Compressing objects:  65% (13/20)        
remote: Compressing objects:  70% (14/20)        
remote: Compressing objects:  75% (15/20)        
remote: Compressing objects:  80% (16/20)        
remote: Compressing objects:  85% (17/20)        
remote: Compressing objects:  90% (18/20)        
remote: Compressing objects:  95% (19/20)        
remote: Compressing objects: 100% (20/20)        
remote: Compressing objects: 100% (20/20), done.        
remote: Total 29 (delta 24), reused 14 (delta 9), pack-reused 0 (from 0)        
From https://github.com/python/cpython
 * branch                    main       -> FETCH_HEAD
Note: switching to '6826166280d6518441a729b444173db205c4ab20'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 6826166280d gh-135801: Improve filtering by module in warn_explicit() without module argument (GH-140151)
Switched to and reset branch 'main'

configure: WARNING: no system libmpdec found; falling back to pure-Python version for the decimal module
configure: WARNING: pkg-config is missing. Some dependencies may not be detected correctly.

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100  192k  100  192k    0     0  1371k      0 --:--:-- --:--:-- --:--:-- 1371k
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100 42455  100 42455    0     0   419k      0 --:--:-- --:--:-- --:--:--  419k
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100 5044k  100 5044k    0     0  21.0M      0 --:--:-- --:--:-- --:--:-- 21.0M
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

 44 1257k   44  556k    0     0  4751k      0 --:--:-- --:--:-- --:--:-- 4751k
100 1257k  100 1257k    0     0  9995k      0 --:--:-- --:--:-- --:--:-- 85.5M
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100  635k  100  635k    0     0  5205k      0 --:--:-- --:--:-- --:--:-- 5205k
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100  479k  100  479k    0     0  3970k      0 --:--:-- --:--:-- --:--:-- 3970k
../../configure: line 4071: pkg-config: command not found
configure: WARNING: no system libmpdec found; falling back to pure-Python version for the decimal module
configure: WARNING: pkg-config is missing. Some dependencies may not be detected correctly.

../../Python/fileutils.c:458:1: warning: unused function 'decode_current_locale' [-Wunused-function]
  458 | decode_current_locale(const char* arg, wchar_t **wstr, size_t *wlen,
      | ^~~~~~~~~~~~~~~~~~~~~
../../Python/fileutils.c:677:1: warning: unused function 'encode_current_locale' [-Wunused-function]
  677 | encode_current_locale(const wchar_t *text, char **str,
      | ^~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
../../Modules/_localemodule.c:195:1: warning: unused function 'is_all_ascii' [-Wunused-function]
  195 | is_all_ascii(const char *str)
      | ^~~~~~~~~~~~
1 warning generated.
../../Modules/pwdmodule.c:69:16: warning: unused variable 'pwd_db_mutex' [-Wunused-variable]
   69 | static PyMutex pwd_db_mutex = {0};
      |                ^~~~~~~~~~~~
1 warning generated.
../../Modules/_hacl/Lib_Memzero0.c:66:6: warning: "Your platform does not support any safe implementation of memzero -- consider a pull request!" [-W#warnings]
   66 |     #warning "Your platform does not support any safe implementation of memzero -- consider a pull request!"
      |      ^
1 warning generated.

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  8784  100  8784    0     0   852k      0 --:--:-- --:--:-- --:--:--  857k
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  2894  100  2894    0     0   394k      0 --:--:-- --:--:-- --:--:--  403k
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 43504  100 43504    0     0  1709k      0 --:--:-- --:--:-- --:--:-- 1770k

@mhsmith
Copy link
Member

mhsmith commented Oct 30, 2025

The Android failure was probably caused by low disk space, as in #138649 (comment). This time there was no CoreSimulator.prev.log, so I had to delete the live CoreSimulator.log (over 20 GB), and then kill
this process to release the open file:

502 45605 1 0 17Jun25 ?? 1253:47.79 /Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/XPCServices/com.apple.CoreSimulator.CoreSimulatorService.xpc/Contents/MacOS/com.apple.CoreSimulator.CoreSimulatorService

It restarted automatically on the next iOS buildbot run.

@freakboy3742: is there any way we can stop this log file from getting so large?

/Users/buildbot/Library/Logs/CoreSimulator also contains 7,000 smaller log files, which is a number that might start causing its own problems (my terminal wasn't very happy when I tried to list them).

@freakboy3742
Copy link
Contributor

The Android failure was probably caused by low disk space, as in #138649 (comment). This time there was no CoreSimulator.prev.log, so I had to delete the live CoreSimulator.log (over 20 GB), and then kill this process to release the open file:

502 45605 1 0 17Jun25 ?? 1253:47.79 /Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/XPCServices/com.apple.CoreSimulator.CoreSimulatorService.xpc/Contents/MacOS/com.apple.CoreSimulator.CoreSimulatorService

It restarted automatically on the next iOS buildbot run.

@freakboy3742: is there any way we can stop this log file from getting so large?

So - I've taken a look at the log file, and it looks like the simulator itself might have gotten into a weird state. The log was filled with errors that indicated problems with missing SDKs and the like.

I've updated the SDK on the buildbot machine, and purged all the simulators except for the one that we're - and now it's not even creating a CoreSimulator.log... so... success? I'll keep an eye on this, but maybe it was just a configuration issue.

/Users/buildbot/Library/Logs/CoreSimulator also contains 7,000 smaller log files, which is a number that might start causing its own problems (my terminal wasn't very happy when I tried to list them).

This looks like it might have been an artefact of the Xcode setup that existed before August. It was creating a cloned simulator every time it ran the test suite; evidently it wasn't cleaning up those clones. I've purged them all, and now there's a single simulator image in that directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants