From 7d153624c3a3543f0b8f906144e35105a5d48801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Fri, 27 Mar 2020 15:13:50 +0000 Subject: The big typing cleanup. Now that Python 3.7 is the minimum Python version, typing can be done inline, which makes it easier for mypy to know the files to check. Indeed, all the files are now typechecked, which uncovered a few minor bugs and mistakes here and there. --- glucometerutils/common.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'glucometerutils/common.py') diff --git a/glucometerutils/common.py b/glucometerutils/common.py index ddb2607..bf944c8 100644 --- a/glucometerutils/common.py +++ b/glucometerutils/common.py @@ -6,7 +6,7 @@ import datetime import enum import textwrap -from typing import Any, Dict, Optional, Sequence +from typing import Any, Dict, Optional, Sequence, Union import attr @@ -91,6 +91,10 @@ class KetoneReading: timestamp: datetime.datetime value: float comment: str = "" + measure_method: MeasurementMethod = attr.ib( + default=MeasurementMethod.BLOOD_SAMPLE, + validator=attr.validators.in_({MeasurementMethod.BLOOD_SAMPLE}), + ) extra_data: Dict[str, Any] = attr.Factory(dict) def as_csv(self, unit: Unit) -> str: @@ -100,7 +104,7 @@ class KetoneReading: return '"%s","%.2f","%s","%s"' % ( self.timestamp, self.value, - MeasurementMethod.BLOOD_SAMPLE.value, + self.measure_method.value, self.comment, ) @@ -123,6 +127,9 @@ class TimeAdjustment: ) +AnyReading = Union[GlucoseReading, KetoneReading, TimeAdjustment] + + @attr.s(auto_attribs=True) class MeterInfo: """General information about the meter. -- cgit v1.2.3