Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Restore the embedded Jython interpreter init#4

Draft
khatchad wants to merge 2 commits into
masterfrom
fix-interpreter-frozen-importlib
Draft

Restore the embedded Jython interpreter init#4
khatchad wants to merge 2 commits into
masterfrom
fix-interpreter-frozen-importlib

Conversation

@khatchad

Copy link
Copy Markdown
Member

Draft — preservation/reference branch, not ready to merge. Tracks wala/ML#580.

Two fixes that get the embedded Jython-3 interpreter initializing again (it currently fails, so all interpreter-based evaluation — constant folding, shape-argument evaluation via interpretAsInt/evalAsInteger — degrades to null):

  • Load frozen_importlib independent of the working directory — the bootstrap resources were read via a cwd-relative FileInputStream, which fails outside the Jython working dir. Loads via classpath → python.home(prefix) → cwd instead. Also bundles the jnr/jffi FFI deps (fat jar) so init doesn't NoClassDefFoundError.
  • Evaluate a string expression as Python str, not bytesPythonInterpreter.eval(String) wrapped the source in PyBytes; __builtin__.eval needs a str/code object (PyUnicode). Regression from the 2016 PEP-393 PyStringPyBytes rename (761f17f).

Why this is a draft, not a merge

Enabling the interpreter installs importlib, which changes how typing.NamedTuple resolves and regresses the downstream NamedTuple-field propagation that just shipped in wala/ML (the constructor field-population gates on NamedTuple being an unresolved/"missing" type). That interaction must be resolved before the interpreter can be turned back on — see wala/ML#580. This branch preserves the init fixes so they aren't lost while that blocker is worked.

🤖 Generated with Claude Code

khatchad and others added 2 commits June 16, 2026 22:22
`PySystemState.doInitialize` read the `_frozen_importlib` bootstrap classes from
a hardcoded working-directory-relative path (`src/resources/frozen_importlib/`),
so interpreter init failed with a `FileNotFoundException` (leaving
`sys.importlib` null) whenever Jython was initialized from any directory other
than the source-tree root — i.e. in a Maven module or OSGi bundle, which is
every real embedding. Resolve via the classpath first, then under
`python.home`, then the legacy relative path.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
`PythonInterpreter.eval(String)` wrapped the source in `PyBytes`, a leftover from
the PEP-393 `PyString`->`PyBytes` rename (761f17f). Python 3's `eval()` requires
a str or code object, so a bytes argument raised "eval: argument 1 must be string
or code object". Wrap in `PyUnicode` instead. Only the `eval(String)` overload was
affected; constant folding goes through `eval(PyObject)`.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@khatchad khatchad changed the title Restore the embedded Jython interpreter init (frozen importlib + str eval) Restore the embedded Jython interpreter init Jun 17, 2026
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.

1 participant