Skip to content

Escape string arguments as Python string literals - #16

Open
ru551n wants to merge 2 commits into
VUnit:mainfrom
ru551n:escape-string-args
Open

ru551n wants to merge 2 commits into
VUnit:mainfrom
ru551n:escape-string-args

Conversation

@ru551n

@ru551n ru551n commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

arg(value : string) and kwarg(kw, value : string) wrapped the text in double quotes verbatim, so a " or \ (or a line break) in the text produced invalid or wrong Python.

Change

Both now build the literal with p_quoted, which escapes ", \, LF and CR, and now also TAB and all other control characters (code < 32 and DEL) as \xNN. Bytes >= 128 are kept as they are so UTF-8 text is decoded by Python as the same characters. python_pkg.vhd is regenerated from the template. The user guide is updated, and the release note is the news fragment release_notes/news.d/16.breaking.md. News fragments are new: towncrier collects them into release_notes/unreleased.md when releasing, and the docs show them under Unreleased.

Behaviour change

Callers that escaped the text themselves (for example passing \n to get a newline) now get that text escaped again, and must pass the plain text instead.

Tests

  • tb_python_pkg_bridge: round trip of quote, backslash, single quote, LF, TAB, CR, NUL, DEL and non-ASCII through arg/kwarg, plus the to_call_str output.
  • tb_python_pkg (also run on VHPI simulators): length/ord checks of escaped strings.
  • Full tests/run.py, the embedded_python example and pytest tests/test_python_bridge.py pass on NVC and GHDL.

🤖 Generated with Claude Code

Comment thread release_notes/unreleased.md Outdated
## Changes

- `import_module_from_file` resolves a relative path against the directory of the testbench file, like `exec_file`, rather than against the working directory of the simulator. It must be called after `test_runner_setup`. Callers that relied on a path relative to the working directory must pass an absolute path instead. See #7.
- `arg(value : string)` and `kwarg(kw, value : string)` now produce a valid Python string literal: quotes, backslashes and control characters in the text are escaped. Callers that escaped the text themselves (for example passing `\\n` to get a newline) now get that text escaped again, and must pass the plain text instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it a news fragment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude (AI assistant) here, on behalf of @ru551n:

Fixed in a482910. The note is now release_notes/news.d/16.breaking.md. The repository had no news fragments yet, so the commit also:

  • configures towncrier ([tool.towncrier] in pyproject.toml, types breaking/feature/bugfix/doc/misc), so towncrier build --version <version> collects the fragments into release_notes/unreleased.md when releasing;
  • shows the fragments under Unreleased in the docs;
  • makes tools/release.py validate --tag fail while fragments are left.

ru551n and others added 2 commits October 15, 2026 09:34
arg and kwarg for string now escape quotes, backslashes and control
characters, so any text round-trips exactly.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The release notes of the next release are now news fragments in
release_notes/news.d, which towncrier collects into
release_notes/unreleased.md when releasing. The documentation shows
them under Unreleased, and the release check fails while any are left.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ru551n
ru551n force-pushed the escape-string-args branch from fa73b4c to a482910 Compare October 15, 2026 07:35

This branch has not been deployed

No deployments
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.

2 participants