Skip to content

Preserve an explicitly supplied falsey AST transformer - #1682

Open
FanWu-ai wants to merge 1 commit into
lark-parser:masterfrom
FanWu-ai:fix/ast-utils-falsey-transformer-oct19
Open

FanWu-ai wants to merge 1 commit into
lark-parser:masterfrom
FanWu-ai:fix/ast-utils-falsey-transformer-oct19

Conversation

@FanWu-ai

Copy link
Copy Markdown

ast_utils.create_transformer() accepts an initial transformer whose existing callbacks are retained while AST constructors are added. It currently replaces that object whenever it is falsey. For example, a transformer implementing __len__ over an initially empty symbol table loses its token/rule callbacks and state, so the same code behaves differently depending on whether the table is populated.

Only construct a new Transformer when the argument is None. Add regression coverage for empty and populated state, preservation of instance identity, existing token and rule callbacks working together with the generated AST constructor, and the omitted/explicit-None defaults.

Validation on Linux:

  • The empty-state regression fails on the unchanged base.
  • Complete Python 3.10 suite, including Nearley: 1,339 tests run, 148 existing conditional skips.
  • Complete Python 3.13 suite: 1,331 tests run, 148 existing conditional skips. Upstream omits Nearley on this interpreter because pinned Js2Py 0.68 cannot import there; the Python 3.10 run covers it.
  • Pinned mypy 1.12: no issues in 34 source files.
  • All applicable configured pre-commit hooks and git diff --check pass.

Other platforms and interpreter versions have not been checked locally. No hosted-CI pass is claimed.

Prepared and tested with OpenAI Codex assistance.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 18, 2026 21:22

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.

1 participant