Skip to content

Commit f7e85ba

Browse files
committed
Fixed type hinting bug.
1 parent 16bf4fa commit f7e85ba

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

simple_rpc/io.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import BinaryIO
1+
from typing import Any, BinaryIO
22
from struct import calcsize, pack, unpack
33

44

@@ -13,7 +13,7 @@ def _read_bytes_until(stream: BinaryIO, delimiter: bytes) -> bytes:
1313
return b''.join(until(lambda x: x == delimiter, stream.read, 1))
1414

1515

16-
def _read_basic(stream: BinaryIO, endianness: str, basic_type: str) -> any:
16+
def _read_basic(stream: BinaryIO, endianness: str, basic_type: str) -> Any:
1717
"""Read a value of basic type from a stream.
1818
1919
:arg stream: Stream object.
@@ -31,7 +31,7 @@ def _read_basic(stream: BinaryIO, endianness: str, basic_type: str) -> any:
3131

3232

3333
def _write_basic(
34-
stream: BinaryIO, endianness: str, basic_type: str, value: any
34+
stream: BinaryIO, endianness: str, basic_type: str, value: Any
3535
) -> None:
3636
"""Write a value of basic type to a stream.
3737
@@ -66,8 +66,8 @@ def cast(c_type: str) -> object:
6666

6767

6868
def read(
69-
stream: BinaryIO, endianness: str, size_t: str, obj_type: any
70-
) -> any:
69+
stream: BinaryIO, endianness: str, size_t: str, obj_type: Any
70+
) -> Any:
7171
"""Read an object from a stream.
7272
7373
:arg stream: Stream object.
@@ -93,8 +93,8 @@ def read_byte_string(stream: BinaryIO) -> bytes:
9393

9494

9595
def write(
96-
stream: BinaryIO, endianness: str, size_t: str, obj_type: any,
97-
obj: any) -> None:
96+
stream: BinaryIO, endianness: str, size_t: str, obj_type: Any,
97+
obj: Any) -> None:
9898
"""Write an object to a stream.
9999
100100
:arg stream: Stream object.

simple_rpc/protocol.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from typing import BinaryIO
1+
from typing import Any, BinaryIO
22

33
from .io import cast, read_byte_string
44

55

6-
def _parse_type(type_str: bytes) -> any:
6+
def _parse_type(type_str: bytes) -> Any:
77
"""Parse a type definition string.
88
99
:arg type_str: Type definition string.
@@ -34,7 +34,7 @@ def _construct_type(tokens: tuple):
3434
return obj_type[0]
3535

3636

37-
def _type_name(obj_type: any) -> str:
37+
def _type_name(obj_type: Any) -> str:
3838
"""Python type name of a C object type.
3939
4040
:arg obj_type: C object type.

simple_rpc/simple_rpc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import wraps
22
from time import sleep
33
from types import MethodType
4-
from typing import TextIO
4+
from typing import Any, TextIO
55

66
from serial import serial_for_url
77
from serial.serialutil import SerialException
@@ -80,7 +80,7 @@ def _select(self: object, index: int) -> None:
8080
"""
8181
self._write('B', index)
8282

83-
def _write(self: object, obj_type: any, obj: any) -> None:
83+
def _write(self: object, obj_type: Any, obj: Any) -> None:
8484
"""Provide parameters for a remote procedure call.
8585
8686
:arg obj_type: Type of the parameter.
@@ -93,7 +93,7 @@ def _write(self: object, obj_type: any, obj: any) -> None:
9393
def _read_byte_string(self: object) -> bytes:
9494
return read_byte_string(self._connection)
9595

96-
def _read(self: object, obj_type: any) -> any:
96+
def _read(self: object, obj_type: Any) -> Any:
9797
"""Read a return value from a remote procedure call.
9898
9999
:arg obj_type: Return type.
@@ -157,7 +157,7 @@ def close(self: object) -> None:
157157
delattr(self, method)
158158
self.device['methods'].clear()
159159

160-
def call_method(self: object, name: str, *args: list) -> any:
160+
def call_method(self: object, name: str, *args: list) -> Any:
161161
"""Execute a method.
162162
163163
:arg name: Method name.
@@ -219,7 +219,7 @@ def _auto_open(f: callable) -> callable:
219219
"""Decorator for automatic opening and closing of ethernet sockets."""
220220
@wraps(f)
221221
def _auto_open_wrapper(
222-
self: object, *args: list, **kwargs: dict) -> any:
222+
self: object, *args: list, **kwargs: dict) -> Any:
223223
self._open()
224224
result = f(self, *args, **kwargs)
225225
self._close()

tests/test_io.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from io import BytesIO
2+
from typing import Any
23

34
from simple_rpc.io import (
45
_read_basic, _read_bytes_until, _write_basic, cast, read, write)
56

67

78
def _test_invariance_basic(
89
f_read: callable, f_write: callable, endianness: str, basic_type: str,
9-
data: bytes, value: any) -> None:
10+
data: bytes, value: Any) -> None:
1011
stream = BytesIO(data)
1112
value_ = f_read(stream, endianness, basic_type)
1213
assert value_ == value
@@ -18,7 +19,7 @@ def _test_invariance_basic(
1819

1920
def _test_invariance(
2021
f_read: callable, f_write: callable, endianness: str, size_t: str,
21-
obj_def: any, data: bytes, obj: any) -> None:
22+
obj_def: Any, data: bytes, obj: Any) -> None:
2223
stream = BytesIO(data)
2324
obj_ = f_read(stream, endianness, size_t, obj_def)
2425
assert obj_ == obj

0 commit comments

Comments
 (0)