Skip to content

Fix tool validation for unpacking aliases in with statements - #2949

Draft
yashwant938 wants to merge 1 commit into
huggingface:mainfrom
yashwant938:fix/2942-with-unpacking-validation
Draft

yashwant938 wants to merge 1 commit into
huggingface:mainfrom
yashwant938:fix/2942-with-unpacking-validation

Conversation

@yashwant938

Copy link
Copy Markdown

Tools using with context() as (left, right) execute successfully but fail export because MethodChecker.visit_With does not register unpacked aliases. Collect ast.Name nodes with ast.Store context from the alias subtree so tuple, list, nested, and starred bindings are recognized. Referenced names in attribute and subscript targets remain subject to undefined-name checks.

Fixes #2942.

This is a draft pending maintainer acceptance of the issue (status:accepted and assignment) and contributor review. Could a maintainer confirm whether this focused change is in scope?

Regression coverage includes ordinary aliases, unpacking aliases, multiple context managers, undefined names, and export/reload of both decorated tools and Tool subclasses.

Validation

Ubuntu under WSL, Python 3.14.4, based on 96f33faaf028479119ec8d34507b47694cf14e34:

  • Before the fix: the standalone reproducer returns 7 when called directly, but export rejects left and right; the validator suite with the added regression cases reports 7 failed and 21 passed.
  • After the fix: the standalone tool returns 7 both before and after export/reload.
  • pytest tests/test_tool_validation.py tests/test_tools.py::TestTool tests/test_tools.py::TestToolDecorator -q -o addopts= --tb=short: 70 passed, including 12 new regression cases.
  • make quality: lint passed and all 77 checked files were already formatted.
  • git diff --check: passed.

The full project suite and the CI Python 3.10/3.12 matrix were not run locally.

AI assistance

OpenAI Codex assisted with implementation, regression tests, local test execution, and PR preparation. This remains a draft pending contributor review of the change and verification results.

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.

BUG: Tool.to_dict rejects valid tuple aliases in with statements as undefined names

1 participant