Skip to content

MAINT MyPy Fails to Find PyRIT Type definitions #720

Closed

Description

@ayeganov

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

Activity

  1. changed the title [-]MyPy Fails to Find PyRit Type definitions[/-] [+]BUG MyPy Fails to Find PyRit Type definitions[/+] on Feb 18, 2025
  2. changed the title [-]BUG MyPy Fails to Find PyRit Type definitions[/-] [+]BUG MyPy Fails to Find PyRIT Type definitions[/+] on Feb 18, 2025
  3. romanlutz commented on Feb 20, 2025

    @romanlutz
    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.

  4. added
    enhancement
    help wanted
    on Feb 20, 2025
  5. changed the title [-]BUG MyPy Fails to Find PyRIT Type definitions[/-] [+]MAINT MyPy Fails to Find PyRIT Type definitions[/+] on Feb 20, 2025
  6. tejas0077 commented on Mar 18, 2026

    @tejas0077
    Contributor

    Hi Roman Lutz (@romanlutz), I'd like to work on this issue!
    I'll start by adding type annotations to the
    common and models modules. Could you please
    assign it to me? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementhelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions