Skip to content

Commit 0c47b01

Browse files
committed
put "import site" and "import warnings" sources into static final fields
1 parent c34fab5 commit 0c47b01

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
import com.oracle.truffle.api.utilities.CyclicAssumption;
107107

108108
public final class PythonContext {
109+
private static final Source IMPORT_WARNINGS_SOURCE = Source.newBuilder(PythonLanguage.ID, "import warnings\n", "<internal>").internal(true).build();
110+
private static final Source FORCE_IMPORTS_SOURCE = Source.newBuilder(PythonLanguage.ID, "import site\n", "<internal>").internal(true).build();
109111
private static final TruffleLogger LOGGER = PythonLanguage.getLogger(PythonContext.class);
110112
private volatile boolean finalizing;
111113

@@ -467,12 +469,12 @@ public void patch(Env newEnv) {
467469

468470
private void importSiteIfForced() {
469471
if (getOption(PythonOptions.ForceImportSite)) {
470-
CallTarget site = env.parsePublic(Source.newBuilder(PythonLanguage.ID, "import site\n", "<internal>").internal(true).build());
472+
CallTarget site = env.parsePublic(FORCE_IMPORTS_SOURCE);
471473
site.call();
472474
}
473475
if (!getOption(PythonOptions.WarnOptions).isEmpty()) {
474476
// we must force an import of the warnings module here if warnings were passed
475-
CallTarget site = env.parsePublic(Source.newBuilder(PythonLanguage.ID, "import warnings\n", "<internal>").internal(true).build());
477+
CallTarget site = env.parsePublic(IMPORT_WARNINGS_SOURCE);
476478
site.call();
477479
}
478480
}

0 commit comments

Comments
 (0)