Skip to content

feat: add type stubs for IDE autocomplete and type checking#13

Merged
shaia merged 1 commit into
masterfrom
feat/add-type-stubs
Dec 5, 2025
Merged

feat: add type stubs for IDE autocomplete and type checking#13
shaia merged 1 commit into
masterfrom
feat/add-type-stubs

Conversation

@shaia
Copy link
Copy Markdown
Owner

@shaia shaia commented Dec 5, 2025

  • Add init.pyi with full type annotations for all functions
  • Add py.typed marker to signal PEP 561 compliance
  • Use modern Python 3.9+ syntax (list, dict, X | None)
  • Enables IDE autocomplete, type hints, and mypy checking

- Add __init__.pyi with full type annotations for all functions
- Add py.typed marker to signal PEP 561 compliance
- Use modern Python 3.9+ syntax (list, dict, X | None)
- Enables IDE autocomplete, type hints, and mypy checking
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds type stubs to enable IDE autocomplete, type hints, and static type checking (e.g., mypy) for the cfd_python C extension module. The implementation uses modern Python 3.9+ syntax and follows PEP 561 for distributable type information.

Key changes:

  • Added comprehensive type annotations for all public functions and constants
  • Included detailed docstrings documenting parameters, return values, and exceptions
  • Created py.typed marker file to signal PEP 561 compliance for type checkers

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.

File Description
cfd_python/py.typed Empty marker file signaling PEP 561 compliance for type checkers
cfd_python/init.pyi Type stub file with full type annotations, function signatures, and comprehensive docstrings for all public APIs including simulation functions, solver discovery, and output functions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cfd_python/__init__.pyi
"""
...

def get_default_solver_params() -> dict[str, float]:
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type annotation for get_default_solver_params() is incorrect. According to the C implementation (src/cfd_python.c:351), the max_iter key contains an integer value (created with PyLong_FromLong), not a float.

The return type should be dict[str, float | int] to accurately reflect that max_iter is an int while other parameters are floats.

Suggested change
def get_default_solver_params() -> dict[str, float]:
def get_default_solver_params() -> dict[str, float | int]:

Copilot uses AI. Check for mistakes.
Comment thread cfd_python/__init__.pyi
- steps: int
- solver_name: str
- solver_description: str
- stats: dict[str, Any]
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring for run_simulation_with_params is incomplete. It's missing two keys that are included in the returned dictionary:

  • output_file (str): Added when the output_file parameter is provided (see src/cfd_python.c:497-501 and tests/test_simulation.py:162)
  • elapsed_time_ms (float): Always included in the stats subdictionary (see src/cfd_python.c:481)

The docstring should document these additional return values to provide accurate type information.

Suggested change
- stats: dict[str, Any]
- stats: dict[str, Any]
- elapsed_time_ms: float
- output_file: str (present only if output_file parameter is provided)

Copilot uses AI. Check for mistakes.
@shaia shaia merged commit d69811e into master Dec 5, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants