MNT: Add type annotations and improve function signatures.#59
Conversation
welli7ngton
commented
Jan 17, 2025
- Enhanced type annotations across botcity/core/bot.py and botcity/core/cv2find.py for better type safety and developer experience.
- Added type hints to parameters and return types in key methods like find, find_all, find_until, and _load_cv2.
- Ensured proper usage of Optional, List, Tuple, and Generator in function definitions.
- Standardized method signatures for consistency, explicitly defining default values and expected data types.
- Updated imports to include necessary types like Union, Optional, List, Tuple, Dict, and Generator.
>> - Enhanced type annotations across botcity/core/bot.py and botcity/core/cv2find.py for better type safety and developer experience. >> - Added type hints to parameters and return types in key methods like find, find_all, find_until, and _load_cv2. >> - Ensured proper usage of Optional, List, Tuple, and Generator in function definitions. >> - Standardized method signatures for consistency, explicitly defining default values and expected data types. >> - Updated imports to include necessary types like Union, Optional, List, Tuple, Dict, and Generator.
|
I'll solve asap, Box is not implemented in python 3.9 |
…m the typing module
|
I’ve attempted to add type annotations to the cv2find module, but I’m not entirely confident that the typings are correct. While working on it in LunarVim, I encountered numerous linter errors, primarily due to conflicts between Black and Flake8. However, when I tested the same in VSCode, everything appeared fine, with no issues reported. Could you please review the typings and confirm if they align with what’s expected? |
botcity/core/bot.py
Outdated
| def find_text( | ||
| self, | ||
| label, | ||
| x=None, | ||
| y=None, | ||
| width=None, | ||
| height=None, | ||
| label: str, | ||
| x: Optional[int] = None, | ||
| y: Optional[int] = None, | ||
| width: Optional[int] = None, | ||
| height: Optional[int] = None, | ||
| *, | ||
| threshold=None, | ||
| matching=0.9, | ||
| waiting_time=10000, | ||
| best=True, | ||
| threshold: Optional[int] = None, | ||
| matching: float = 0.9, | ||
| waiting_time: int = 10000, | ||
| best: bool = True, | ||
| ): |
There was a problem hiding this comment.
Return type is missing
|
@welli7ngton great work with the computer vision methods! Just a small suggestion, I think that in methods like This way, we can keep the code more readable, and if there is any future update to the structure of the "Box" named tuple, we will not need to change it in each method. |
|
Overall, I ran some tests using the computer vision methods, and everything seemed to work fine! Just as a reference, I printed the element and the return type in the code for each method I tested, and these were the results: Feel free to use it as a reference or even do more tests if you want. |
|
@joao-voltarelli fixed! thanks for the attention |
I'll work on it, thanks for the suggestion! |
…d get_last_element to cv2find.Box to improve code readability
|
@welli7ngton Thanks for the contribution! |