diff options
-rw-r--r-- | glucometerutils/common.py | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/glucometerutils/common.py b/glucometerutils/common.py index c11ff2c..8b41320 100644 --- a/glucometerutils/common.py +++ b/glucometerutils/common.py @@ -8,7 +8,7 @@ import enum import textwrap try: - from typing import Optional, Sequence, Text + from typing import Optional, Sequence except ImportError: pass @@ -57,15 +57,16 @@ def convert_glucose_unit(value, from_unit, to_unit): @attr.s class GlucoseReading: - timestamp = attr.ib() # type: datetime.datetime - value = attr.ib() # type: float + timestamp = attr.ib(type=datetime.datetime) + value = attr.ib(type=float) meal = attr.ib( - default=Meal.NONE, validator=attr.validators.in_(Meal)) # type: Meal - comment = attr.ib(default='') # type: Text + default=Meal.NONE, validator=attr.validators.in_(Meal), + type=Meal) + comment = attr.ib(default='', type=str) measure_method = attr.ib( default=MeasurementMethod.BLOOD_SAMPLE, - validator=attr.validators.in_( - MeasurementMethod)) # type: MeasurementMethod + validator=attr.validators.in_(MeasurementMethod), + type=MeasurementMethod) extra_data = attr.ib(factory=dict) def get_value_as(self, to_unit): @@ -78,7 +79,7 @@ class GlucoseReading: return convert_glucose_unit(self.value, Unit.MG_DL, to_unit) def as_csv(self, unit): - # type: (Unit) -> Text + # type: (Unit) -> str """Returns the reading as a formatted comma-separated value string.""" return '"%s","%.2f","%s","%s","%s"' % ( self.timestamp, self.get_value_as(unit), self.meal.value, @@ -87,9 +88,9 @@ class GlucoseReading: @attr.s class KetoneReading: - timestamp = attr.ib() # type: datetime.datetime - value = attr.ib() # type: float - comment = attr.ib(default='') # type: Text + timestamp = attr.ib(type=datetime.datetime) + value = attr.ib(type=float) + comment = attr.ib(default='', type=str) extra_data = attr.ib(factory=dict) def as_csv(self, unit): @@ -129,12 +130,13 @@ class MeterInfo: the device. It can include hardware and software version. native_unit: One of the Unit values to identify the meter native unit. """ - model = attr.ib() # type: Text - serial_number = attr.ib(default='N/A') # type: Text - version_info = attr.ib(default=()) # type: Sequence[Text] + model = attr.ib(type=str) + serial_number = attr.ib(default='N/A', type=str) + version_info = attr.ib(default=(), type=Sequence[str]) native_unit = attr.ib( - default=Unit.MG_DL, validator=attr.validators.in_(Unit)) # type: Unit - patient_name = attr.ib(default=None) # type: Optional[Text] + default=Unit.MG_DL, validator=attr.validators.in_(Unit), + type=Unit) + patient_name = attr.ib(default=None, type=Optional[str]) def __str__(self): version_information_string = 'N/A' |