gh-158684: Remove ineffective lazy import of sysconfig from ctypes - #158793
sillyfellow21 wants to merge 1 commit into
Conversation
| ) | ||
|
|
||
|
|
||
| class StdlibLazyImportTests(LazyImportTestCase): |
There was a problem hiding this comment.
That's not the approriatae place for the test I think. It is likely in to be done in test_ctypes as we usually do for other modules. Avoid using LLM if the output is not properly revieweed.
| import sys as _sys | ||
| import types as _types | ||
|
|
||
| lazy import sysconfig as _sysconfig |
There was a problem hiding this comment.
Isn't this lazy import still correct for other platforms? I don't think it's an issue per se though? many imports can be lazy because a single function uses them but if no one is using the function we still have a lazy pending import so I don't understand why this should be removed.
picnixz
left a comment
There was a problem hiding this comment.
I am not accepting this change as is. What we can accept is a test for lazy imports in test_ctypes. Plese look at other test modules to understand how to do it.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be poked with soft cushions! |
Fixes gh-158684.
Root cause
Lib/ctypes/__init__.pydeclared a lazy import ofsysconfig:but the only uses of
_sysconfigwere at module scope, inside theandroidandcygwinbranches of thepythonapisetup:Reading a lazily imported name reifies that import immediately, so the lazy import was not lazy at all on those two platforms, and on every other platform nothing ever resolved it: it just sat in
sys.lazy_modulesforever. Either way the laziness bought nothing, and retaining an unresolvable pending entry is the bug reported in gh-158684.Change
Drop the lazy import and do a plain conditional
import sysconfigin the two branches that actually need it.sysconfigis now loaded on Android/Cygwin and is neither loaded nor retained anywhere else. Behaviour is otherwise unchanged: the same twoget_config_var()calls produce the samepythonapion the same two platforms.Tests
Added
test.test_lazy_import.StdlibLazyImportTests.test_ctypes_does_not_leave_sysconfig_pending, which importsctypesin a subprocess and assertssysconfigis not left insys.lazy_modules.Results on 3.15.0rc3 with these files copied over its
Lib/:ctypes: FAIL -AssertionError: ['locale', 'pkgutil', 'sysconfig', 'traceback', 'warnings']ctypes: oktest.test_lazy_import: 162 tests, OKtest.test_ctypes: 675 tests, OK (40 skipped)ctypes.pythonapi.Py_GetVersion()still worksgit diff --checkis clean and the committed blobs are LF.Note on validation scope: this machine has no MSVC toolchain (
cl.exe), so I could not run a native CPython build ormake patchcheck. The change is pure-Python and the suites above were run against a 3.15.0rc3 interpreter, not against amainbuild; the Android and Cygwin branches themselves could not be exercised here since this is Windows.