fix #29059, unnecessary warning in precompile for eval
in __init__
#29134
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Load-time
eval
into a different module is not allowed, since its results can't be tracked and saved. Init-time and run-timeeval
are allowed.__init__
methods are the only code expected to run during precompilation that are not "load time" code. So technically, the eval warning could be disabled at init-time. We don't have a good way to do that though, so instead I chose to set current_module toX
while runningX.__init__
. That at least allowsX
to eval into itself, which is the most sensible case.Incidentally, I believe this warning is the only remaining use for the
current_module
stuff. I'll make a separate PR to remove unnecessary setting/resetting of it.I also made a slight change to the logic controlling when to run
__init__
methods. Previously we did it (1) after loading a precompiled module, or (2) once we are back outside of any module. E.g. these modules:used to print
true
in precompiled mode, butfalse
in--compiled-modules=no
mode. The change makes it always printtrue
, by considering any full package to be sufficiently "top level".fixes #29059