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

MAINT MyPy Fails to Find PyRIT Type definitions #720

Open
ayeganov opened this issue Feb 17, 2025 · 1 comment
Open

MAINT MyPy Fails to Find PyRIT Type definitions #720

ayeganov opened this issue Feb 17, 2025 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ayeganov
Copy link
Contributor

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

  1. Setup a poetry project
  2. Add pyrit poetry add pyrit
  3. Add code to your project where you import pyrit modules: from pyrit.memory.memory_interface import MemoryInterface
  4. Setup mypy in your poetry project:
[tool.mypy]
python_version = "3.12"
  1. 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
@romanlutz romanlutz changed the title MyPy Fails to Find PyRit Type definitions BUG MyPy Fails to Find PyRit Type definitions Feb 18, 2025
@romanlutz romanlutz changed the title BUG MyPy Fails to Find PyRit Type definitions BUG MyPy Fails to Find PyRIT Type definitions Feb 18, 2025
@romanlutz
Copy link
Contributor

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.

@romanlutz romanlutz added enhancement New feature or request help wanted Extra attention is needed labels Feb 20, 2025
@romanlutz romanlutz changed the title BUG MyPy Fails to Find PyRIT Type definitions MAINT MyPy Fails to Find PyRIT Type definitions Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants