From 28e83654b2d6a706e1d54b60c4391fc5093efa1f Mon Sep 17 00:00:00 2001 From: alphahm Date: Sat, 6 Apr 2024 01:18:02 +0100 Subject: [PATCH] minimal type checking --- .github/workflows/test.yml | 3 +++ .gitignore | 3 ++- requirements.txt | 3 ++- src/adhanpy/PrayerTimes.py | 10 +++++----- src/adhanpy/calculation/CalculationParameters.py | 6 +++--- src/adhanpy/calculation/MethodsParameters.py | 5 +++-- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d335eb4..9b0b4a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,6 +24,9 @@ jobs: - name: lint run: | black --check src/ + - name: mypy + run: | + mypy src - name: Test with pytest run: | pytest diff --git a/.gitignore b/.gitignore index 646eedf..ae69b78 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ venv dist build .coverage -.idea \ No newline at end of file +.idea +*.swp diff --git a/requirements.txt b/requirements.txt index ca178ce..b89ae35 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ black==22.6.0 pytest==7.1.2 pytest-cov==3.0.0 -pytest-mock==3.8.2 \ No newline at end of file +pytest-mock==3.8.2 +mypy==1.9.0 diff --git a/src/adhanpy/PrayerTimes.py b/src/adhanpy/PrayerTimes.py index 2e0e168..e873aea 100644 --- a/src/adhanpy/PrayerTimes.py +++ b/src/adhanpy/PrayerTimes.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta, timezone +from typing import Optional from zoneinfo import ZoneInfo -from typing import Tuple from adhanpy.calculation.CalculationMethod import CalculationMethod from adhanpy.calculation.CalculationParameters import CalculationParameters from adhanpy.calculation.Twilight import ( @@ -18,11 +18,11 @@ class PrayerTimes: def __init__( self, - coordinates: Tuple[float, float], + coordinates: tuple[float, float], date: datetime, - calculation_method: CalculationMethod = None, - calculation_parameters: CalculationParameters = None, - time_zone: ZoneInfo = None, + calculation_method: Optional[CalculationMethod] = None, + calculation_parameters: Optional[CalculationParameters] = None, + time_zone: Optional[ZoneInfo] = None, ): """ Arguments: diff --git a/src/adhanpy/calculation/CalculationParameters.py b/src/adhanpy/calculation/CalculationParameters.py index 7aca4b0..314d9c7 100644 --- a/src/adhanpy/calculation/CalculationParameters.py +++ b/src/adhanpy/calculation/CalculationParameters.py @@ -1,6 +1,6 @@ -from typing import Optional +from typing import Any, Optional from adhanpy.calculation.CalculationMethod import CalculationMethod -from adhanpy.calculation.MethodsParameters import methods_parameters +from adhanpy.calculation.MethodsParameters import METHODS_PARAMETERS from adhanpy.calculation.Madhab import Madhab from adhanpy.calculation.HighLatitudeRule import HighLatitudeRule from adhanpy.calculation.PrayerAdjustments import PrayerAdjustments @@ -62,6 +62,6 @@ def night_portions(self) -> NightPortions: raise ValueError("Invalid high latitude rule") def _set_parameters_using_method(self) -> None: - method_parameters = methods_parameters[self.method] + method_parameters = METHODS_PARAMETERS[self.method] for key, value in method_parameters.items(): setattr(self, key, value) diff --git a/src/adhanpy/calculation/MethodsParameters.py b/src/adhanpy/calculation/MethodsParameters.py index e0d2967..f8ec8f0 100644 --- a/src/adhanpy/calculation/MethodsParameters.py +++ b/src/adhanpy/calculation/MethodsParameters.py @@ -1,8 +1,9 @@ +from typing import Any + from adhanpy.calculation.CalculationMethod import CalculationMethod from adhanpy.calculation.PrayerAdjustments import PrayerAdjustments - -methods_parameters = { +METHODS_PARAMETERS: dict[CalculationMethod, dict[str, Any]] = { CalculationMethod.NONE: {}, CalculationMethod.MUSLIM_WORLD_LEAGUE: { "fajr_angle": 18.0,