Skip to content
Permalink
Browse files

Experimentally start adding type annotations, and mypy configs.

This cannot currently be added to CI because the lack of `construct` stubs,
which cause "unsupported left operands" for /-constructed structs.
  • Loading branch information...
Flameeyes committed Dec 12, 2018
1 parent 46765e9 commit 4f4635e06b2ec0504bda0d6f2552bf72bb218aa0
Showing with 38 additions and 13 deletions.
  1. +3 −2 .gitignore
  2. +4 −4 glucometerutils/support/freestyle.py
  3. +9 −4 glucometerutils/support/hiddevice.py
  4. +8 −3 glucometerutils/support/serial.py
  5. +14 −0 mypy.ini
@@ -1,8 +1,9 @@
*.egg-info/
*.pyc
*~
.cache
.mypy_cache/
/MANIFEST
/dist/
__pycache__/
.cache
build
*.egg-info/
@@ -77,8 +77,8 @@ class FreeStyleHidDevice(hiddevice.HidDevice):
TEXT_CMD = 0x60
TEXT_REPLY_CMD = 0x60

USB_VENDOR_ID = 0x1a61 # Abbott Diabetes Care
USB_PRODUCT_ID = None
USB_VENDOR_ID = 0x1a61 # type: int # Abbott Diabetes Care
USB_PRODUCT_ID = None # type: int

def connect(self):
"""Open connection to the device, starting the knocking sequence."""
@@ -103,8 +103,8 @@ def _send_command(self, message_type, command):
usb_packet = _FREESTYLE_MESSAGE.build(
{'message_type': message_type, 'command': command})

logging.debug('Sending packet: %r', usb_packet)

logging.debug('Sending packet: %r', usb_packet
)
self._write(usb_packet)

def _read_response(self):
@@ -9,6 +9,11 @@
import logging
import os

try:
from typing import Optional
except:
pass

from glucometerutils import exceptions


@@ -33,14 +38,14 @@ class HidDevice(object):
Optional parameters available:
TIMEOUT_MS: (int, default: NOne) the read timeout in milliseconds, used
TIMEOUT_MS: (int, default: None) the read timeout in milliseconds, used
for hidapi reads only. If -1, hidapi will be provided no timeout.
"""

USB_VENDOR_ID = None
USB_PRODUCT_ID = None
USB_VENDOR_ID = None # type: int
USB_PRODUCT_ID = None # type: int

TIMEOUT_MS = None
TIMEOUT_MS = None # type: Optional[int]

def __init__(self, device):
if None in (self.USB_VENDOR_ID, self.USB_PRODUCT_ID) and not device:
@@ -9,6 +9,11 @@

import logging

try:
from typing import Text
except:
pass

import serial

from glucometerutils import exceptions
@@ -40,10 +45,10 @@ class SerialDevice(object):
"""

BAUDRATE = None
DEFAULT_CABLE_ID = None
BAUDRATE = None # type: int
DEFAULT_CABLE_ID = None # type: Text

TIMEOUT = 1
TIMEOUT = 1 # type: float

def __init__(self, device):
assert self.BAUDRATE is not None
@@ -0,0 +1,14 @@
[mypy]
python_version = 3.7

[mypy-serial]
ignore_missing_imports = True

[mypy-construct]
ignore_missing_imports = True

[mypy-hid]
ignore_missing_imports = True

[mypy-pyscsi.*]
ignore_missing_imports = True

0 comments on commit 4f4635e

Please sign in to comment.
You can’t perform that action at this time.