Skip to content

Add comprehensive type hints to SCORE2 module #8

@fbraza

Description

@fbraza

Issue Description

The SCORE2 implementation is missing type hints for some variables and could benefit from more comprehensive typing.

Current State

  • Function signatures have type hints
  • Some internal variables lack type hints
  • Could improve code clarity and IDE support

Suggested Improvements

1. Add type hints for transformed variables

# Current
cage = (age - 60) / 5
smoking = float(biomarkers.smoking)

# Improved
cage: float = (age - 60) / 5
smoking: float = float(biomarkers.smoking)
csbp: float = (biomarkers.systolic_blood_pressure - 120) / 20
ctchol: float = biomarkers.total_cholesterol - 6
chdl: float = (biomarkers.hdl_cholesterol - 1.3) / 0.5

2. Add type hints for interaction terms

smoking_age: float = smoking * cage
sbp_age: float = csbp * cage
tchol_age: float = ctchol * cage
hdl_age: float = chdl * cage

3. Add type hints for intermediate calculations

x: float = (...)  # Linear predictor
uncalibrated_risk: float = 1 - np.power(baseline_survival, np.exp(x))

4. Consider using TypeAlias for risk categories

from typing import Literal, TypeAlias

RiskCategory: TypeAlias = Literal["Low to moderate", "High", "Very high"]

Impact

  • Better IDE support and code completion
  • Easier to understand variable types at a glance
  • Helps catch type-related bugs early
  • Improves code maintainability

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions