-
-
Notifications
You must be signed in to change notification settings - Fork 50k
Add missing type hints to hill_climbing.py #14260
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
base: master
Are you sure you want to change the base?
Add missing type hints to hill_climbing.py #14260
Conversation
This commit adds the missing type annotations to searches/hill_climbing.py. - Added type annotation for function_to_optimize using Callable [[int, int], int] - Added return type hints to get_neighbors, __hash__, __eq__, and __str__ - Added missing type hint for search_prob in hill_climbing() - Improved type clarity while preserving existing logic - Used modern Python type hints (PEP 585) This improves readability and typing consistency across the repository.
for more information, see https://pre-commit.ci
llukito
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a suggestion regarding the type hints for the objective function.
searches/hill_climbing.py
Outdated
| x: int, | ||
| y: int, | ||
| step_size: int, | ||
| function_to_optimize: Callable[[int, int], int], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work adding these hints!
I have one suggestion regarding function_to_optimize: Currently, it is typed to return an int (Callable[[int, int], int]). However, in optimization problems, objective functions very often return float values (costs, fitness scores, etc.).
Restricting it to int might flag valid use cases as errors. Would it be safer to type it as Callable[[int, int], float] or Callable[[int, int], int | float]?
llukito
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update!
|
The CI failure confirms that the int | float change is correct, but we missed the return type hint for the score() method (or whichever method is at line 42). You just need to update that method's return annotation to -> int | float so it matches the input function. |
Mypy reported an incompatible return type because function_to_optimize may return float values. Updated score() return type from int to int | float for full compatibility.
|
Thanks for the suggestion! |
This PR adds missing type hints to searches/hill_climbing.py.
Improves readability and typing consistency across the repository.
Describe your change:
Checklist: