-
Notifications
You must be signed in to change notification settings - Fork 538
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
Use linting to detect code errors #340
Comments
Please note that Python is a dynamically typed language and the use of type hints in the smolagents library is optional: we do not enforce strict static typing. IMO, implementing strict static typing is not a priority. I think it is better to focus on adding more interesting features. By the way, we are already using ruff as linter and formatter! |
Of course, I understand that Python is dynamically typed and that is why it's called type hints. The smolagents library doesn't seem to be different to any other project in that respect. It's like unit tests, you can see them as a chore or a helpful tool. Typing hints can be a communication tool to developers. But it can also be a helpful tool to spot errors. But they are always optional as you say and you can use it as much or little as you want. This GitHub issue wasn't about adding type hints though. It was about using linters to help spot errors in the existing code. There are already many typing hints within Perhaps sometimes
Understood. From the documentation itself, Please correct me if I am wrong, but it seems that From my experience, these tools can be useful tools so that you can then focus more on adding interesting features. |
It might be a good idea to use linting in ci to catch errors early. Common tools used are
pylint
andmypy
.You could ignore all of
pylint
's Python style recommendations and just look for errors.e.g.:
And you get a few potential errors (I filtered some out):
The
assignment-from-no-return
stem from thestep
function not being declared asabstractmethod
(you might argue that as a style).In the following code pylint says
observation_name
might be used before assignment becauseobservation_type
could possibly neither beAgentImage
norAgentAudio
:And in
parse_json_tool_call
themypy
also shows a lot of warnings, some may just be incorrect type hints (which is hard to always get right if not automatically checked). Not sure if any of those indicate other coding errors.I found adding
mypy
(or any linting) early can make it really much easier than adding it later on.(Over the time I also personally warmed to many of the style recommendations)
The text was updated successfully, but these errors were encountered: