PyRIT
PyRIT copied to clipboard
MAINT MyPy Fails to Find PyRIT Type definitions
Describe the bug
In my poetry project I had to set these settings:
[[tool.mypy.overrides]]
module = ["pyrit.*"]
ignore_missing_imports = true
If I don't ignore pyrit then I get these errors:
proj/memory/storage.py:10: error: Skipping analyzing "pyrit.common": module is installed, but missing library stubs or py.typed marker [import-untyped]
proj/memory/storage.py:11: error: Skipping analyzing "pyrit.models": module is installed, but missing library stubs or py.typed marker [import-untyped]
Steps/Code to Reproduce
- Setup a poetry project
- Add pyrit
poetry add pyrit - Add code to your project where you import pyrit modules:
from pyrit.memory.memory_interface import MemoryInterface - Setup mypy in your poetry project:
[tool.mypy]
python_version = "3.12"
- Run mypy:
poetry run mypy --strict project.
Expected Results
Expect no mypy issues related to pyrit types
Actual Results
error: Skipping analyzing "pyrit.memory": module is installed, but missing library stubs or py.typed marker [import-untyped]
Screenshots
Versions
pyrit = {git = "https://github.com/Azure/PyRIT.git", rev = "c254a9f038517a7df58d7979bf8c9ab0976a88a4"}
Python dependencies:
pyrit: 0.5.3.dev0
Cython: None
numpy: 2.2.3
openai: 1.62.0
pip: 24.0
scikit-learn: 1.6.1
scipy: 1.15.1
setuptools: 75.8.0
tensorflow: None
torch: None
transformers: 4.48.3
Thank you for filing the issue! We don't need poetry to repro. Our pyproject.toml has a section [tool.mypy]. strict = true and other settings can be tweaked.
Even just running mypy with strict manually spits out a lot of things to fix
python -m mypy .\pyrit\common\ --strict
pyrit\common\utils.py:8: error: Missing type parameters for generic type "dict" [type-arg]
pyrit\common\utils.py:25: error: Missing type parameters for generic type "list" [type-arg]
pyrit\common\text_helper.py:7: error: Function is missing a type annotation for one or more arguments [no-untyped-def]
pyrit\common\text_helper.py:11: error: Function is missing a return type annotation [no-untyped-def]
pyrit\common\text_helper.py:11: error: Function is missing a type annotation for one or more arguments [no-untyped-def]
pyrit\common\singleton.py:13: error: Missing type parameters for generic type "dict" [type-arg]
pyrit\common\singleton.py:15: error: Function is missing a type annotation [no-untyped-def]
pyrit\common\csv_helper.py:8: error: Function is missing a type annotation for one or more arguments [no-untyped-def]
pyrit\common\csv_helper.py:13: error: Function is missing a return type annotation [no-untyped-def]
pyrit\common\csv_helper.py:13: error: Function is missing a type annotation for one or more arguments [no-untyped-def]
pyrit\common\json_helper.py:8: error: Function is missing a type annotation for one or more arguments [no-untyped-def]
pyrit\common\json_helper.py:9: error: Returning Any from function declared to return "list[dict[str, str]]" [no-any-return]
pyrit\common\json_helper.py:12: error: Function is missing a return type annotation [no-untyped-def]
pyrit\common\json_helper.py:12: error: Function is missing a type annotation for one or more arguments [no-untyped-def]
pyrit\common\net_utility.py:10: error: Function is missing a return type annotation [no-untyped-def]
pyrit\common\net_utility.py:56: error: Returning Any from function declared to return "Response" [no-any-return]
...
Whoever picks this up should look into at least common and models, but ideally turn strict on for all of pyrit via the toml file.