Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor evaluate ast to improve readability #625

Merged
merged 3 commits into from
Feb 18, 2025

Conversation

CalOmnie
Copy link
Contributor

This PR does 3 main things:

  • create a common_params variable for use instead of retyping state, static_tools, custom_tools, authorized_imports every time
  • Replace the elif machine with a match statement
  • Create evaluate_ast_partial, a partial evaluation of evaluate_ast allowing it to be used with map

I'll concede the later 2 are more of an opinionated choice than a straight improvement to readability, let me know if you think so too and I'll discard them.

raise InterpreterError(f"{expression.__class__.__name__} is not supported.")
common_params = (state, static_tools, custom_tools, authorized_imports)
evaluate_ast_partial = partial(evaluate_ast, state=state, static_tools=static_tools, custom_tools=custom_tools, authorized_imports=authorized_imports)
match expression:
Copy link
Contributor

Choose a reason for hiding this comment

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

This requires python >= 3.10. Wonder if maintainers are ok with this 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it is a fair concern, I checked in the project's pyproject.toml and the Python version is requires-python = ">=3.10" so it should be fine, but if this refactor is the only thing preventing the project from handling python 3.9 it's a tough sell.

Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly, no idea. They don't use tox here to test against different versions. I guess we need to add that. Maybe that ship has already sailed and adding matching is fine :)

@CalOmnie CalOmnie force-pushed the refactor-evaluate-ast branch from 3ce7c97 to 093a54f Compare February 17, 2025 18:22
@CalOmnie
Copy link
Contributor Author

@albertvillanova I noticed this change was not getting much traction so I changed it to its most basic form. Let me know if that works for you.

Copy link
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

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

Hi, it seems you didn't run the quality checks before pushing your PR.

Here you can find the contributing guideline: https://github.com/huggingface/smolagents/blob/main/CONTRIBUTING.md

@CalOmnie
Copy link
Contributor Author

Hey @albertvillanova thanks for taking the time to look at this, I did run the quality checks, but not with the same command as the CI, hence the discrepancy (I did make quality instead of uv run ruff format examples src tests utils)

This is fixed now, is there an issue tracking the update of the Makefile/pyproject to add a dependency on uv/update the targets? I can pick that up if you guys are a bit tight on bandwidth.

Copy link
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

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

Thanks.

@albertvillanova albertvillanova merged commit 4e05fab into huggingface:main Feb 18, 2025
1 of 3 checks passed
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.

3 participants