From 09f042fb0abfe0dd4d5a60d9fba6eeff3e80cb4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Mon, 2 Sep 2019 19:04:04 +0100 Subject: Use type= parameters in attr.ib() declarations. This should work just as well and makes it read a little better. Also, replace Text references with str, since we don't support Python 2 anyway. --- glucometerutils/common.py | 34 ++++++++++++++++++---------------- 1 file 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' -- cgit v1.2.3