diff --git a/Makefile b/Makefile index c8e7c04f6..3f6a32f94 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: quality style test docs utils +.PHONY: quality style test docs utils mypy check_dirs := examples src tests utils @@ -6,8 +6,15 @@ check_dirs := examples src tests utils 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 diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 000000000..ae385cf7e --- /dev/null +++ b/mypy.ini @@ -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 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 266717318..8630e96c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 @@ -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"]