Skip to content

Add Python Type Hints to the ai_bom.scanner module #65

@Zie619

Description

@Zie619

Description

This issue aims to improve the code quality and maintainability of the ai_bom.scanner module by adding Python type hints. Type hints make the code easier to understand, debug, and refactor, especially for new contributors.

The ai_bom.scanner module is responsible for scanning AI/ML projects and gathering information about their dependencies and components. Adding type hints to this module will clarify the expected input and output types of its functions and classes.

Acceptance Criteria

  • All functions and methods within the ai_bom.scanner module have complete and accurate type hints, including: argument types, return types, and variable types.
  • The code should still pass all existing unit tests after adding type hints. If any tests fail due to type hints, update the tests accordingly.
  • The type hints should be PEP 484 compliant.
  • The code should be formatted with a tool like black or ruff after adding type hints.
  • No new dependencies should be introduced.

Suggested Approach

  1. Familiarize yourself with the ai_bom.scanner module: Read the code in ai_bom/scanner.py to understand its structure and functionality.
  2. Add type hints: Start by adding type hints to the function arguments and return values. Then, add type hints to local variables where necessary.
  3. Run type checker: Use a type checker like mypy to verify the correctness of the type hints. Run mypy ai_bom/scanner.py (you might need to install mypy first pip install mypy).
  4. Address type errors: If mypy reports any errors, correct the type hints or the code to resolve them.
  5. Run unit tests: Ensure that all existing unit tests still pass after adding type hints. Run pytest from the project root.
  6. Format the code: Use a code formatter like black or ruff to ensure consistent code style. Run black ai_bom/scanner.py or ruff format ai_bom/scanner.py.
  7. Commit and create a pull request: Commit your changes with a descriptive message and create a pull request.

Additional Context

  • If you are new to Python type hints, refer to the official Python documentation: https://docs.python.org/3/library/typing.html
  • Feel free to ask questions and seek help from the project maintainers if you encounter any difficulties.
  • The existing codebase might already use type hints partially, please be consistent and complete the process for the entire module.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions