Skip to content

Handle broad visitor callback annotations#19

Open
jeet-dekivadia wants to merge 1 commit into
hudson-trading:mainfrom
jeet-dekivadia:accept-broad-visitor-callbacks
Open

Handle broad visitor callback annotations#19
jeet-dekivadia wants to merge 1 commit into
hudson-trading:mainfrom
jeet-dekivadia:accept-broad-visitor-callbacks

Conversation

@jeet-dekivadia

Copy link
Copy Markdown

Fixes #18.

_VisitorFuncWrapper uses the first callback parameter annotation as an optional runtime filter. Concrete node annotations work, but callbacks with no annotation silently skip every node because inspect.Parameter.empty is treated as a filter value. Callbacks annotated as Any raise TypeError because typing.Any cannot be used with isinstance().

This normalizes both cases to the existing visit-all path while leaving concrete typed callbacks unchanged. The regression covers an unannotated callback and an Any callback against the same expression tree.

Validation:

  • git diff --check
  • .venv/bin/python -m pytest test/stdlib/acceptance_test.py::test_broad_visitor_functions_visit_all_nodes
  • uv format --diff
  • uv run --all-extras --dev pytest
  • uv run --all-extras --dev mypy heracles

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.

Visitor callbacks without a concrete annotation do not visit nodes

1 participant