Skip to content

feat(py/var-config): expose a pure parse_var_config(text, source)#19

Open
AndreasKoestler wants to merge 1 commit into
varar-dev:mainfrom
AndreasKoestler:fix/issue-11-py-parse
Open

feat(py/var-config): expose a pure parse_var_config(text, source)#19
AndreasKoestler wants to merge 1 commit into
varar-dev:mainfrom
AndreasKoestler:fix/issue-11-py-parse

Conversation

@AndreasKoestler

Copy link
Copy Markdown
Contributor

Closes #11.

TypeScript exposes parseVarConfig(jsonText, sourcePath) and Java VarConfig.parse(String, String) — pure text parsers separated from the file-reading edge. Python's read_var_config(root) fused read + parse, so there was no way to parse config text without a file on disk.

Change

  • Add parse_var_config(text: str, source: str) -> VarConfig — a pure function (no file I/O) that validates config text and labels every ValueError with the given source. This is the functional core, mirroring the other ports.
  • Reimplement read_var_config(root) on top of it: it now only touches the filesystem (missing file → empty config; else read text and delegate), passing str(path) as the source so error messages are byte-for-byte unchanged.
  • Export parse_var_config from the package.

Tests

  • Added a direct test that parse_var_config parses inline text with no file present, and that it labels errors with the caller-supplied source.
  • Existing file-based tests and the shared config conformance suite stay green (18 + 8 passing); ruff check/format clean.

🤖 Generated with Claude Code

Split config parsing from the file-reading edge, mirroring TypeScript's
parseVarConfig(jsonText, sourcePath) and Java's VarConfig.parse(String,
String). parse_var_config(text, source) is a pure function that validates
config text and labels every error with the given source; read_var_config
is now the thin imperative shell that reads the file and delegates to it.
Callers can now parse config text without a file on disk.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aslakhellesoy

Copy link
Copy Markdown
Contributor

Hi @AndreasKoestler - thanks a lot!

You accidentally added the unrelated Rust port to this PR. Could you separate it please?

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.

Python var_config: expose a pure parse(text, source) like TS/Java

2 participants