Skip to content

Commit

Permalink
More type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Mar 31, 2022
1 parent d13f5fd commit e306a6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
21 changes: 13 additions & 8 deletions pyxcp/constants.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import struct
from typing import Callable
from typing import NewType

PackerType = NewType("PackerType", Callable[[int], bytes])
UnpackerType = NewType("UnpackerType", Callable[[bytes], int])

def makeBytePacker(byteorder="@"):

def makeBytePacker(byteorder: str = "@") -> PackerType:
""""""
return struct.Struct("{}B".format(byteorder)).pack


def makeByteUnpacker(byteorder="@"):
def makeByteUnpacker(byteorder: str = "@") -> UnpackerType:
""""""
return struct.Struct("{}B".format(byteorder)).unpack


def makeWordPacker(byteorder="@"):
def makeWordPacker(byteorder: str = "@") -> PackerType:
""""""
return struct.Struct("{}H".format(byteorder)).pack


def makeWordUnpacker(byteorder="@"):
def makeWordUnpacker(byteorder: str = "@") -> UnpackerType:
""""""
return struct.Struct("{}H".format(byteorder)).unpack


def makeDWordPacker(byteorder="@"):
def makeDWordPacker(byteorder: str = "@") -> PackerType:
""""""
return struct.Struct("{}I".format(byteorder)).pack


def makeDWordUnpacker(byteorder="@"):
def makeDWordUnpacker(byteorder: str = "@") -> UnpackerType:
""""""
return struct.Struct("{}I".format(byteorder)).unpack


def makeDLongPacker(byteorder="@"):
def makeDLongPacker(byteorder: str = "@") -> PackerType:
""""""
return struct.Struct("{}Q".format(byteorder)).pack


def makeDLongUnpacker(byteorder="@"):
def makeDLongUnpacker(byteorder: str = "@") -> UnpackerType:
""""""
return struct.Struct("{}Q".format(byteorder)).unpack
5 changes: 4 additions & 1 deletion pyxcp/master/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@
from pyxcp.constants import makeDWordUnpacker
from pyxcp.constants import makeWordPacker
from pyxcp.constants import makeWordUnpacker
from pyxcp.constants import PackerType
from pyxcp.constants import UnpackerType
from pyxcp.master.errorhandler import disable_error_handling
from pyxcp.master.errorhandler import wrapped
from pyxcp.transport.base import createTransport
from pyxcp.utils import delay
from time import sleep
from typing import Callable


def broadcasted(func):
def broadcasted(func: Callable):
""""""
return func

Expand Down

0 comments on commit e306a6e

Please sign in to comment.