Skip to content

Add Python Type Hints to the scanner Module #78

@Zie619

Description

@Zie619

Description

This issue focuses on enhancing the code quality and maintainability of the ai-bom project by adding Python type hints to the scanner module. Type hints improve code readability, help catch potential errors during development, and enable better tooling support (e.g., static analysis).

Acceptance Criteria

  • All functions and methods within the ai_bom/scanner.py file have been annotated with appropriate type hints.
  • Type hints cover function arguments, return values, and variable assignments where applicable and beneficial.
  • The codebase passes type checking using mypy without any errors or warnings.
  • Existing unit tests still pass after adding type hints.
  • The added type hints are consistent with the existing codebase and Python best practices.

Suggested Approach

  1. Set up your development environment:
    • Clone the ai-bom repository.
    • Create a virtual environment: python -m venv venv
    • Activate the virtual environment: source venv/bin/activate (Linux/macOS) or venv\Scripts\activate (Windows)
    • Install the development dependencies, including mypy: pip install -e .[dev]
  2. Explore the ai_bom/scanner.py file:
    • Understand the functionality of each function and class within the module.
  3. Add type hints:
    • Start adding type hints to function arguments and return values. For example:
      def scan_directory(directory: str) -> list[str]:
          # ...
    • Add type hints to variables within functions where it improves clarity.
    • Use Any type hint sparingly and only when the type cannot be determined.
  4. Run mypy to check for type errors:
    • Execute mypy ai_bom/scanner.py in the terminal.
    • Fix any errors reported by mypy.
    • Repeat steps 3 and 4 until mypy reports no errors.
  5. Run existing unit tests:
    • Execute pytest in the terminal.
    • Ensure all tests pass after adding type hints. Fix any failing tests if necessary.
  6. Commit and create a pull request:
    • Commit your changes with a clear message (e.g., "feat: Add type hints to scanner module").
    • Create a pull request to the main branch.

Additional Context

The scanner module is responsible for discovering and analyzing components within AI/ML projects. It's a critical part of ai-bom, so adding type hints will significantly improve its maintainability. Make sure to refer to the Python documentation on type hints for more information: https://docs.python.org/3/library/typing.html. If you are unsure about the correct type hint to use, feel free to ask for clarification in the pull request.

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