Skip to content

fix: -f runs a Python program, and an integer indexes a list - #244

Merged
jonruttan merged 2 commits into
mainfrom
fix/batch-file
Nov 20, 2026
Merged

jonruttan merged 2 commits into
mainfrom
fix/batch-file

Conversation

@jonruttan

Copy link
Copy Markdown
Owner

Two defects of x -l python as a user runs it, neither of which the suite could show. Two commits.

1. -f runs a Python program

x -l python -f PROGRAM.py read the program as x-lang:

$ x -l python -f one.py        # print(1 + 1)
Error: Unbound SYMBOL 'print'

The wrapper cats the file after this bundle's entry and runs the platform's batch loop over the stream. The entry chose a loop for a session only.

  • run.x: the last form asks the wrapper's seam whether a file was supplied, and calls python-batch.
  • python/repl.x, python-batch: reads what is left of the stream as the program and runs it whole. No banner, no prompt, no echo of an expression's value; a blank line ends nothing.
  • Bytes. A line is kept as its bytes, so a program's UTF-8 is not encoded twice.
  • Standard input. Put back from fd 3, where the wrapper parks it.
  • Errors. One the program does not catch is on standard error, with status 1.

A file of (python-run ...) forms given with -f is no longer read: -f means Python. tests/boot.sh was the one caller found.

2. An integer index on a list

Under x -l python:

>>> a = [9, 3, 1]
>>> a[1]
TypeError: list indices must be integers or slices, not float

So did a[-1], and [][1] in place of its IndexError. Slices and tuples were not affected.

python/types.x took the float type's handle with (type-of 1.5) as it loaded, and it loads before the tower. On the dialect lang.xon declares, 1.5 is not read as a float there, so the handle was an integer's. The handle is bound in python/runtime-num.x now, where the tower is loaded.

Why the suite passed

  • The suite loads the bundle on the full-tower amalgam, where 1.5 is a float from the start.
  • tests/boot.sh, which boots the declared dialect, gave -f a file of python-run forms and indexed no list.

tests/boot.sh now gives -f a Python file with a blank line inside a block, an expression statement and a list index, and a second file that raises.

Verified

On v0.59.0:

x-python: x -l python boots from source on the declared dialect and runs a program
x-python: a program that raises ends with status 1 and its error on standard error

Seventeen Python programs through -f from a state image, each compared with what CPython prints (the card draft that found both):

card: ok (384 rows, 1 shell rows run, 17 programs run, 0 rows in other fences not run here)

Not verified

  • The spec suite was not run here; CI runs it.
  • __file__ is not set and an import looks in the working directory, not beside the program: the wrapper cats the file and its name does not reach the bundle.
  • raise SystemExit(N) ends with status 0, as python-run has it.
  • A program on standard input with no -f still gets the banner and the prompts.

🤖 Generated with Claude Code

jonruttan and others added 2 commits November 20, 2026 11:10
x -l python -f PROGRAM.py read the program as x-lang: print(1 + 1)
answered Unbound SYMBOL 'print'. The wrapper cats the file after this
bundle's entry and runs the platform's batch loop over the stream, and
the entry chose a loop for a session only.

The entry's last form now asks the wrapper's seam whether a file was
supplied, and python-batch (python/repl.x) reads what is left of the
stream as the program and runs it whole: no banner, no prompt, no echo
of an expression's value, and a blank line ends nothing. A line is kept
as its bytes, so a program's UTF-8 is not encoded twice. The program's
standard input is put back from fd 3. An error it does not catch is on
standard error, with status 1.

tests/boot.sh gave -f a file of python-run forms, which is why it
passed. It gives it a Python file now, with a blank line inside a block
and an expression statement, and a second one that raises.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Under x -l python, a[1] on a list raised TypeError: list indices must be
integers or slices, not float. So did a[-1], and [][1] in place of its
IndexError.

python/types.x took the float type's handle with (type-of 1.5) as it
loaded, and it loads before the tower. On the dialect lang.xon declares,
1.5 is not read as a float there, so the handle was an integer's and the
list subscript's float check held for every integer.

The handle is bound in python/runtime-num.x, where the tower is loaded.
The suite's amalgam has the tower from the start and did not show it;
tests/boot.sh, which boots the declared dialect, indexes a list now.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jonruttan
jonruttan merged commit 176ec58 into main Nov 20, 2026
12 checks passed
@jonruttan
jonruttan deleted the fix/batch-file branch November 20, 2026 21:06
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