summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.com>2023-08-03 12:26:51 +0200
committerDiego Elio Pettenò <flameeyes@flameeyes.com>2023-08-03 12:47:49 +0200
commit093a39d72dbc7d18c0aacbdd5a4ba6a04cd64f95 (patch)
tree69db3bac569d41ef0e073ac36d2b66144417e6e2
parentUpdate minimum supported Python version to 3.9. (diff)
downloadglucometerutils-093a39d72dbc7d18c0aacbdd5a4ba6a04cd64f95.tar
glucometerutils-093a39d72dbc7d18c0aacbdd5a4ba6a04cd64f95.tar.gz
glucometerutils-093a39d72dbc7d18c0aacbdd5a4ba6a04cd64f95.tar.bz2
glucometerutils-093a39d72dbc7d18c0aacbdd5a4ba6a04cd64f95.tar.lz
glucometerutils-093a39d72dbc7d18c0aacbdd5a4ba6a04cd64f95.tar.xz
glucometerutils-093a39d72dbc7d18c0aacbdd5a4ba6a04cd64f95.tar.zst
glucometerutils-093a39d72dbc7d18c0aacbdd5a4ba6a04cd64f95.zip
-rw-r--r--glucometerutils/common.py9
-rw-r--r--glucometerutils/driver.py7
-rw-r--r--glucometerutils/drivers/accuchek_reports.py7
-rw-r--r--glucometerutils/drivers/contourusb.py5
-rw-r--r--glucometerutils/drivers/fsinsulinx.py3
-rw-r--r--glucometerutils/drivers/fsoptium.py3
-rw-r--r--glucometerutils/drivers/fsprecisionneo.py5
-rw-r--r--glucometerutils/drivers/glucomenareo.py5
-rw-r--r--glucometerutils/drivers/otultra2.py2
-rw-r--r--glucometerutils/drivers/otultraeasy.py5
-rw-r--r--glucometerutils/drivers/otverio2015.py5
-rw-r--r--glucometerutils/drivers/otverioiq.py5
-rw-r--r--glucometerutils/drivers/sdcodefree.py3
-rw-r--r--glucometerutils/drivers/td42xx.py5
-rw-r--r--glucometerutils/support/contourusb.py9
-rw-r--r--glucometerutils/support/freestyle_libre.py9
-rw-r--r--glucometerutils/support/hiddevice.py4
17 files changed, 53 insertions, 38 deletions
diff --git a/glucometerutils/common.py b/glucometerutils/common.py
index 51a2dd4..24bc0d1 100644
--- a/glucometerutils/common.py
+++ b/glucometerutils/common.py
@@ -7,7 +7,8 @@
import datetime
import enum
import textwrap
-from typing import Any, Dict, Optional, Sequence, Union
+from collections.abc import Sequence
+from typing import Any, Optional, Union
import attr
@@ -64,7 +65,7 @@ class GlucoseReading:
default=MeasurementMethod.BLOOD_SAMPLE,
validator=attr.validators.in_(MeasurementMethod),
)
- extra_data: Dict[str, Any] = attr.Factory(dict)
+ extra_data: dict[str, Any] = attr.Factory(dict)
def get_value_as(self, to_unit: Unit) -> float:
"""Returns the reading value as the given unit.
@@ -94,7 +95,7 @@ class KetoneReading:
default=MeasurementMethod.BLOOD_SAMPLE,
validator=attr.validators.in_({MeasurementMethod.BLOOD_SAMPLE}),
)
- extra_data: Dict[str, Any] = attr.Factory(dict)
+ extra_data: dict[str, Any] = attr.Factory(dict)
def as_csv(self, unit: Unit) -> str:
"""Returns the reading as a formatted comma-separated value string."""
@@ -115,7 +116,7 @@ class TimeAdjustment:
measure_method: MeasurementMethod = attr.ib(
default=MeasurementMethod.TIME, validator=attr.validators.in_(MeasurementMethod)
)
- extra_data: Dict[str, Any] = attr.Factory(dict)
+ extra_data: dict[str, Any] = attr.Factory(dict)
def as_csv(self, unit: Unit) -> str:
del unit
diff --git a/glucometerutils/driver.py b/glucometerutils/driver.py
index 88556d8..5f524e9 100644
--- a/glucometerutils/driver.py
+++ b/glucometerutils/driver.py
@@ -8,13 +8,14 @@ import dataclasses
import datetime
import importlib
import inspect
-from typing import Generator, Optional, Text, Type
+from collections.abc import Generator
+from typing import Optional
from glucometerutils import common
class GlucometerDevice(abc.ABC):
- def __init__(self, device_path: Optional[Text]) -> None:
+ def __init__(self, device_path: Optional[str]) -> None:
pass
def connect(self) -> None:
@@ -72,7 +73,7 @@ class GlucometerDevice(abc.ABC):
@dataclasses.dataclass
class Driver:
- device: Type[GlucometerDevice]
+ device: type[GlucometerDevice]
help: str
diff --git a/glucometerutils/drivers/accuchek_reports.py b/glucometerutils/drivers/accuchek_reports.py
index 5c56597..161f8a7 100644
--- a/glucometerutils/drivers/accuchek_reports.py
+++ b/glucometerutils/drivers/accuchek_reports.py
@@ -19,7 +19,8 @@ import csv
import datetime
import glob
import os
-from typing import Dict, Generator, NoReturn, Optional
+from collections.abc import Generator
+from typing import NoReturn, Optional
from glucometerutils import common, driver, exceptions
@@ -112,7 +113,7 @@ class Device(driver.GlucometerDevice):
raise NotImplementedError
def _extract_datetime(
- self, record: Dict[str, str]
+ self, record: dict[str, str]
) -> datetime.datetime: # pylint: disable=no-self-use
# Date and time are in separate column, but we want to parse them
# together.
@@ -120,7 +121,7 @@ class Device(driver.GlucometerDevice):
return datetime.datetime.strptime(date_and_time, _DATETIME_FORMAT)
def _extract_meal(
- self, record: Dict[str, str]
+ self, record: dict[str, str]
) -> common.Meal: # pylint: disable=no-self-use
if record[_AFTER_MEAL_CSV_KEY] and record[_BEFORE_MEAL_CSV_KEY]:
raise exceptions.InvalidResponse("Reading cannot be before and after meal.")
diff --git a/glucometerutils/drivers/contourusb.py b/glucometerutils/drivers/contourusb.py
index 9161aa1..578a1a6 100644
--- a/glucometerutils/drivers/contourusb.py
+++ b/glucometerutils/drivers/contourusb.py
@@ -20,13 +20,14 @@ http://protocols.ascensia.com/Programming-Guide.aspx
"""
import datetime
-from typing import Dict, Generator, NoReturn, Optional
+from collections.abc import Generator
+from typing import NoReturn, Optional
from glucometerutils import common
from glucometerutils.support import contourusb
-def _extract_timestamp(parsed_record: Dict[str, str]):
+def _extract_timestamp(parsed_record: dict[str, str]):
"""Extract the timestamp from a parsed record.
This leverages the fact that all the reading records have the same base structure.
diff --git a/glucometerutils/drivers/fsinsulinx.py b/glucometerutils/drivers/fsinsulinx.py
index 89d10d6..71a8508 100644
--- a/glucometerutils/drivers/fsinsulinx.py
+++ b/glucometerutils/drivers/fsinsulinx.py
@@ -19,7 +19,8 @@ Xavier Claessens.
import collections
import datetime
-from typing import Generator, NoReturn, Optional
+from collections.abc import Generator
+from typing import NoReturn, Optional
from glucometerutils import common
from glucometerutils.support import freestyle
diff --git a/glucometerutils/drivers/fsoptium.py b/glucometerutils/drivers/fsoptium.py
index e1054c1..abd7309 100644
--- a/glucometerutils/drivers/fsoptium.py
+++ b/glucometerutils/drivers/fsoptium.py
@@ -20,7 +20,8 @@ https://protocols.glucometers.tech/abbott/freestyle-optium
import datetime
import logging
import re
-from typing import Generator, NoReturn, Sequence
+from collections.abc import Generator, Sequence
+from typing import NoReturn
from glucometerutils import common, driver, exceptions
from glucometerutils.support import serial
diff --git a/glucometerutils/drivers/fsprecisionneo.py b/glucometerutils/drivers/fsprecisionneo.py
index ddec9b2..8e5b803 100644
--- a/glucometerutils/drivers/fsprecisionneo.py
+++ b/glucometerutils/drivers/fsprecisionneo.py
@@ -24,7 +24,8 @@ https://protocols.glucometers.tech/abbott/freestyle-precision-neo
import dataclasses
import datetime
-from typing import Generator, NoReturn, Optional, Sequence, Type
+from collections.abc import Generator, Sequence
+from typing import NoReturn, Optional
from glucometerutils import common
from glucometerutils.support import freestyle
@@ -85,7 +86,7 @@ class Device(freestyle.FreeStyleHidDevice):
def get_readings(self) -> Generator[common.AnyReading, None, None]:
"""Iterate through the reading records in the device."""
for record in self._session.query_multirecord(b"$result?"):
- cls: Optional[Type[common.AnyReading]] = None
+ cls: Optional[type[common.AnyReading]] = None
if record and record[0] == _TYPE_GLUCOSE_READING:
cls = common.GlucoseReading
elif record and record[0] == _TYPE_KETONE_READING:
diff --git a/glucometerutils/drivers/glucomenareo.py b/glucometerutils/drivers/glucomenareo.py
index ca903e0..82a645f 100644
--- a/glucometerutils/drivers/glucomenareo.py
+++ b/glucometerutils/drivers/glucomenareo.py
@@ -13,7 +13,8 @@ Expected device path: /dev/ttyUSB0 or similar serial port device.
import dataclasses
import datetime
import logging
-from typing import Generator, Iterator, List, Mapping, NoReturn, Sequence, Union
+from collections.abc import Generator, Iterator, Mapping, Sequence
+from typing import NoReturn, Union
import crcmod.predefined
import serial as pyserial
@@ -100,7 +101,7 @@ class Device(serial.SerialDevice, driver.GlucometerDevice):
return line
def _read_text_response(self) -> Sequence[bytes]:
- all_lines: List[bytes] = []
+ all_lines: list[bytes] = []
while True:
line = self._readline()
diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py
index 56138b9..5a1b355 100644
--- a/glucometerutils/drivers/otultra2.py
+++ b/glucometerutils/drivers/otultra2.py
@@ -16,7 +16,7 @@ Expected device path: /dev/ttyUSB0 or similar serial port device.
import datetime
import re
-from typing import Generator
+from collections.abc import Generator
from glucometerutils import common, driver, exceptions
from glucometerutils.support import lifescan, serial
diff --git a/glucometerutils/drivers/otultraeasy.py b/glucometerutils/drivers/otultraeasy.py
index ec834f0..b0aa093 100644
--- a/glucometerutils/drivers/otultraeasy.py
+++ b/glucometerutils/drivers/otultraeasy.py
@@ -19,7 +19,8 @@ Expected device path: /dev/ttyUSB0 or similar serial port device.
import binascii
import datetime
import logging
-from typing import Any, Dict, Generator, Optional
+from collections.abc import Generator
+from typing import Any, Optional
import construct
@@ -178,7 +179,7 @@ class Device(serial.SerialDevice, driver.GlucometerDevice):
def _send_request(
self,
request_format: construct.Struct,
- request_obj: Optional[Dict[str, Any]],
+ request_obj: Optional[dict[str, Any]],
response_format: construct.Struct,
) -> construct.Container:
try:
diff --git a/glucometerutils/drivers/otverio2015.py b/glucometerutils/drivers/otverio2015.py
index b7b4c93..76f3c84 100644
--- a/glucometerutils/drivers/otverio2015.py
+++ b/glucometerutils/drivers/otverio2015.py
@@ -26,7 +26,8 @@ https://protocols.glucometers.tech/lifescan/onetouch-verio-2015
import binascii
import datetime
import logging
-from typing import Any, Dict, Generator, Optional
+from collections.abc import Generator
+from typing import Any, Optional
import construct
from pyscsi.pyscsi.scsi import SCSI
@@ -141,7 +142,7 @@ class Device(driver.GlucometerDevice):
self,
lba: int,
request_format: construct.Struct,
- request_obj: Optional[Dict[str, Any]],
+ request_obj: Optional[dict[str, Any]],
response_format: construct.Struct,
) -> construct.Container:
"""Send a request to the meter, and read its response.
diff --git a/glucometerutils/drivers/otverioiq.py b/glucometerutils/drivers/otverioiq.py
index a5a7553..0d297dc 100644
--- a/glucometerutils/drivers/otverioiq.py
+++ b/glucometerutils/drivers/otverioiq.py
@@ -19,7 +19,8 @@ auto-detected.
import binascii
import datetime
import logging
-from typing import Any, Dict, Generator, Optional
+from collections.abc import Generator
+from typing import Any, Optional
import construct
@@ -125,7 +126,7 @@ class Device(serial.SerialDevice, driver.GlucometerDevice):
def _send_request(
self,
request_format: construct.struct,
- request_obj: Optional[Dict[str, Any]],
+ request_obj: Optional[dict[str, Any]],
response_format: construct.Struct,
) -> construct.Container:
try:
diff --git a/glucometerutils/drivers/sdcodefree.py b/glucometerutils/drivers/sdcodefree.py
index 33eb21d..098468b 100644
--- a/glucometerutils/drivers/sdcodefree.py
+++ b/glucometerutils/drivers/sdcodefree.py
@@ -22,7 +22,8 @@ import enum
import functools
import logging
import operator
-from typing import Generator, NoReturn
+from collections.abc import Generator
+from typing import NoReturn
import construct
diff --git a/glucometerutils/drivers/td42xx.py b/glucometerutils/drivers/td42xx.py
index 80df118..ac901a3 100644
--- a/glucometerutils/drivers/td42xx.py
+++ b/glucometerutils/drivers/td42xx.py
@@ -19,7 +19,8 @@ import enum
import functools
import logging
import operator
-from typing import Generator, NoReturn, Optional, Tuple
+from collections.abc import Generator
+from typing import NoReturn, Optional
import construct
@@ -152,7 +153,7 @@ class Device(serial.SerialDevice, driver.GlucometerDevice):
command: int,
message: bytes = _EMPTY_MESSAGE,
validate_response: bool = True,
- ) -> Tuple[int, bytes]:
+ ) -> tuple[int, bytes]:
pkt = _make_packet(command, message)
logging.debug("sending packet: %s", binascii.hexlify(pkt))
diff --git a/glucometerutils/support/contourusb.py b/glucometerutils/support/contourusb.py
index c61ab41..259e8d1 100644
--- a/glucometerutils/support/contourusb.py
+++ b/glucometerutils/support/contourusb.py
@@ -15,7 +15,8 @@ http://protocols.ascensia.com/Programming-Guide.aspx
import datetime
import enum
import re
-from typing import Dict, Generator, List, Optional, Tuple
+from collections.abc import Generator
+from typing import Optional
from glucometerutils import driver
from glucometerutils.support import hiddevice
@@ -80,7 +81,7 @@ class ContourHidDevice(driver.GlucometerDevice):
currecno: Optional[int] = None
- def __init__(self, usb_ids: Tuple[int, int], device_path: Optional[str]) -> None:
+ def __init__(self, usb_ids: tuple[int, int], device_path: Optional[str]) -> None:
super().__init__(device_path)
self._hid_session = hiddevice.HidSession(usb_ids, device_path)
@@ -315,13 +316,13 @@ class ContourHidDevice(driver.GlucometerDevice):
except Exception as e:
raise e
- def parse_result_record(self, text: str) -> Dict[str, str]:
+ def parse_result_record(self, text: str) -> dict[str, str]:
result = _RESULT_RECORD_RE.search(text)
assert result is not None
rec_text = result.groupdict()
return rec_text
- def _get_multirecord(self) -> List[Dict[str, str]]:
+ def _get_multirecord(self) -> list[dict[str, str]]:
"""Queries for, and returns, "multirecords" results.
Returns:
diff --git a/glucometerutils/support/freestyle_libre.py b/glucometerutils/support/freestyle_libre.py
index 46ecf15..b231449 100644
--- a/glucometerutils/support/freestyle_libre.py
+++ b/glucometerutils/support/freestyle_libre.py
@@ -12,7 +12,8 @@ https://protocols.glucometers.tech/abbott/freestyle-libre
import datetime
import logging
-from typing import Dict, Generator, Mapping, Optional, Sequence, Tuple, Type
+from collections.abc import Generator, Mapping, Sequence
+from typing import Optional
from glucometerutils import common, exceptions
from glucometerutils.support import freestyle
@@ -67,8 +68,8 @@ _ARRESULT_RAPID_INSULIN_ENTRY_MAP = ((43, "double-rapid-acting-insulin"),)
def _parse_record(
- record: Sequence[str], entry_map: Sequence[Tuple[int, str]]
-) -> Dict[str, int]:
+ record: Sequence[str], entry_map: Sequence[tuple[int, str]]
+) -> dict[str, int]:
"""Parses a list of string fields into a dictionary of integers."""
if not record:
@@ -127,7 +128,7 @@ def _parse_arresult(record: Sequence[str]) -> Optional[common.AnyReading]:
comment_parts = []
measure_method: Optional[common.MeasurementMethod] = None
- cls: Optional[Type[common.AnyReading]] = None
+ cls: Optional[type[common.AnyReading]] = None
value: Optional[float] = None
if parsed_record["reading-type"] == 2:
diff --git a/glucometerutils/support/hiddevice.py b/glucometerutils/support/hiddevice.py
index bd35a8f..eb069df 100644
--- a/glucometerutils/support/hiddevice.py
+++ b/glucometerutils/support/hiddevice.py
@@ -7,7 +7,7 @@
import logging
import os
-from typing import BinaryIO, Optional, Tuple
+from typing import BinaryIO, Optional
from glucometerutils import exceptions
@@ -23,7 +23,7 @@ class HidSession:
def __init__(
self,
- usb_id: Optional[Tuple[int, int]],
+ usb_id: Optional[tuple[int, int]],
device: Optional[str],
timeout_ms: int = 0,
) -> None: