Skip to content

Commit

Permalink
Experimentally start adding type annotations, and mypy configs.
Browse files Browse the repository at this point in the history
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 4f4635e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
5 changes: 3 additions & 2 deletions .gitignore
@@ -1,8 +1,9 @@
*.egg-info/
*.pyc
*~
.cache
.mypy_cache/
/MANIFEST
/dist/
__pycache__/
.cache
build
*.egg-info/
8 changes: 4 additions & 4 deletions glucometerutils/support/freestyle.py
Expand Up @@ -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."""
Expand All @@ -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):
Expand Down
13 changes: 9 additions & 4 deletions glucometerutils/support/hiddevice.py
Expand Up @@ -9,6 +9,11 @@
import logging
import os

try:
from typing import Optional
except:
pass

from glucometerutils import exceptions


Expand All @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions glucometerutils/support/serial.py
Expand Up @@ -9,6 +9,11 @@

import logging

try:
from typing import Text
except:
pass

import serial

from glucometerutils import exceptions
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions mypy.ini
@@ -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.