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

Enable Mypy check #845

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
.PHONY: quality style test docs utils
.PHONY: quality style test docs utils mypy

check_dirs := examples src tests utils

# Check code quality of the source code
quality:
ruff check $(check_dirs)
ruff format --check $(check_dirs)
# disabling mypy in standard quality check for now.
# Reenable it when the code base get a good state
# mypy $(check_dirs)
python utils/check_tests_in_ci.py

# Run mypy type checking
mypy:
mypy $(check_dirs)

# Format source code automatically
style:
ruff check $(check_dirs) --fix
Expand Down
53 changes: 53 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[mypy]
python_version = 3.10
warn_return_any = True
warn_unused_configs = True
disallow_untyped_defs = False
disallow_incomplete_defs = False
check_untyped_defs = True
disallow_untyped_decorators = False
no_implicit_optional = True
strict_optional = True

# Ignore missing imports for external libraries
[mypy.plugins.numpy.*]
ignore_missing_imports = True

[mypy-IPython.*]
ignore_missing_imports = True

[mypy-soundfile.*]
ignore_missing_imports = True

[mypy-gradio_client.*]
ignore_missing_imports = True

[mypy-gradio.*]
ignore_missing_imports = True

[mypy-mcpadapt.*]
ignore_missing_imports = True

[mypy-accelerate.*]
ignore_missing_imports = True

[mypy-mlx_lm.*]
ignore_missing_imports = True

[mypy-litellm.*]
ignore_missing_imports = True

[mypy-openai.*]
ignore_missing_imports = True

[mypy-e2b_code_interpreter.*]
ignore_missing_imports = True

[mypy-websocket.*]
ignore_missing_imports = True

[mypy-helium.*]
ignore_missing_imports = True

[mypy-selenium.*]
ignore_missing_imports = True
44 changes: 44 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ all = [
]
quality = [
"ruff>=0.9.0",
"mypy>=1.9.0",
"types-requests",
"types-PyYAML",
"types-docker"
]
test = [
"ipython>=8.31.0", # for interactive environment tests
Expand Down Expand Up @@ -106,6 +110,46 @@ lint.select = ["E", "F", "I", "W"]
known-first-party = ["smolagents"]
lines-after-imports = 2

[tool.mypy]
python_version = "3.10"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = false
disallow_incomplete_defs = false
check_untyped_defs = true
disallow_untyped_decorators = false
no_implicit_optional = true
strict_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_no_return = true
warn_unreachable = true

[[tool.mypy.overrides]]
module = [
"torch.*",
"transformers.*",
"pillow.*",
"huggingface_hub.*",
"pandas.*",
"duckduckgo_search.*",
"markdownify.*",
"IPython.*",
"soundfile.*",
"gradio_client.*",
"gradio.*",
"mcpadapt.*",
"accelerate.*",
"mlx_lm.*",
"litellm.*",
"openai.*",
"e2b_code_interpreter.*",
"websocket.*",
"helium.*",
"selenium.*"
]
ignore_missing_imports = true

[tool.setuptools.package-data]
"smolagents.prompts" = ["*.yaml"]

Expand Down