Skip to content

Commit cd34d4d

Browse files
author
BiffoBear
committed
Standardised on Optional. Added __future__ as required. All modules import. Added # pylint: disable=cyclic-import
1 parent fb19126 commit cd34d4d

File tree

6 files changed

+40
-26
lines changed

6 files changed

+40
-26
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def socket_available(self, socket_num: int, sock_type: int = SNMR_TCP) -> int:
645645
return ret
646646
return 0
647647

648-
def socket_status(self, socket_num: int) -> Union[bytearray, None]:
648+
def socket_status(self, socket_num: int) -> Optional[bytearray]:
649649
"""
650650
Return the socket connection status.
651651
@@ -656,7 +656,7 @@ def socket_status(self, socket_num: int) -> Union[bytearray, None]:
656656
657657
:param int socket_num: ID of socket to check.
658658
659-
:return: Union[bytearray, None]
659+
:return: Optional[bytearray]
660660
"""
661661
return self._read_snsr(socket_num)
662662

@@ -1087,12 +1087,12 @@ def _read_sntx_wr(self, sock: int) -> int:
10871087
self._pbuff[1] = self._read_socket(sock, 0x0024 + 1)[0]
10881088
return self._pbuff[0] << 8 | self._pbuff[1]
10891089

1090-
def _read_sntx_fsr(self, sock: int) -> Union[bytearray, None]:
1090+
def _read_sntx_fsr(self, sock: int) -> Optional[bytearray]:
10911091
data = self._read_socket(sock, REG_SNTX_FSR)
10921092
data += self._read_socket(sock, REG_SNTX_FSR + 1)
10931093
return data
10941094

1095-
def _read_snrx_rsr(self, sock: int) -> Union[bytearray, None]:
1095+
def _read_snrx_rsr(self, sock: int) -> Optional[bytearray]:
10961096
data = self._read_socket(sock, REG_SNRX_RSR)
10971097
data += self._read_socket(sock, REG_SNRX_RSR + 1)
10981098
return data
@@ -1107,7 +1107,7 @@ def _write_sndport(self, sock: int, port: int) -> None:
11071107
self._write_socket(sock, REG_SNDPORT, port >> 8)
11081108
self._write_socket(sock, REG_SNDPORT + 1, port & 0xFF)
11091109

1110-
def _read_snsr(self, sock: int) -> Union[bytearray, None]:
1110+
def _read_snsr(self, sock: int) -> Optional[bytearray]:
11111111
"""Read Socket n Status Register."""
11121112
return self._read_socket(sock, REG_SNSR)
11131113

@@ -1127,10 +1127,10 @@ def _write_sock_port(self, sock: int, port: int) -> None:
11271127
def _write_sncr(self, sock: int, data: int) -> None:
11281128
self._write_socket(sock, REG_SNCR, data)
11291129

1130-
def _read_sncr(self, sock: int) -> Union[bytearray, None]:
1130+
def _read_sncr(self, sock: int) -> Optional[bytearray]:
11311131
return self._read_socket(sock, REG_SNCR)
11321132

1133-
def _read_snmr(self, sock: int) -> Union[bytearray, None]:
1133+
def _read_snmr(self, sock: int) -> Optional[bytearray]:
11341134
return self._read_socket(sock, REG_SNMR)
11351135

11361136
def _write_socket(self, sock: int, address: int, data: int) -> None:
@@ -1145,7 +1145,7 @@ def _write_socket(self, sock: int, address: int, data: int) -> None:
11451145
)
11461146
return None
11471147

1148-
def _read_socket(self, sock: int, address: int) -> Union[bytearray, None]: # *1
1148+
def _read_socket(self, sock: int, address: int) -> Optional[bytearray]: # *1
11491149
"""Read a W5k socket register."""
11501150
if self._chip_type == "w5500":
11511151
cntl_byte = (sock << 5) + 0x08

adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
* Author(s): Jordan Terrell, Brent Rubell
1414
1515
"""
16+
from __future__ import annotations
17+
1618
try:
1719
from typing import Optional, Union, Tuple, Sequence
1820

21+
# pylint: disable=cyclic-import
22+
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
1923
except ImportError:
2024
pass
2125

@@ -90,7 +94,7 @@ class DHCP:
9094
# pylint: disable=too-many-arguments, too-many-instance-attributes, invalid-name
9195
def __init__(
9296
self,
93-
eth,
97+
eth: WIZNET5K,
9498
mac_address: Sequence[Union[int, bytes]],
9599
hostname: Optional[str] = None,
96100
response_timeout: float = 30,

adafruit_wiznet5k/adafruit_wiznet5k_dns.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@
1313
* Author(s): MCQN Ltd, Brent Rubell
1414
1515
"""
16+
from __future__ import annotations
17+
1618
try:
1719
from typing import Union, Tuple
20+
21+
# pylint: disable=cyclic-import
22+
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
1823
except ImportError:
1924
pass
2025

@@ -24,7 +29,6 @@
2429
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
2530
from adafruit_wiznet5k.adafruit_wiznet5k_socket import htons
2631

27-
2832
QUERY_FLAG = const(0x00)
2933
OPCODE_STANDARD_QUERY = const(0x00)
3034
RECURSION_DESIRED_FLAG = 1 << 8
@@ -48,7 +52,7 @@ class DNS:
4852

4953
def __init__(
5054
self,
51-
iface,
55+
iface: WIZNET5K,
5256
dns_address: Union[str, Tuple[int, int, int, int]],
5357
debug: bool = False,
5458
) -> None:

adafruit_wiznet5k/adafruit_wiznet5k_ntp.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
1818
1919
"""
20+
from __future__ import annotations
21+
2022
try:
2123
import typing # pylint: disable=unused-import
24+
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
2225
except ImportError:
2326
pass
2427
import time
@@ -33,7 +36,7 @@ class NTP:
3336

3437
def __init__(
3538
self,
36-
iface,
39+
iface: WIZNET5K,
3740
ntp_address: str,
3841
utc: int,
3942
debug: bool = False,

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
* Author(s): ladyada, Brent Rubell, Patrick Van Oosterwijck, Adam Cummick
1313
1414
"""
15+
from __future__ import annotations
16+
1517
try:
1618
from typing import Any, Optional, Tuple, List, Union
19+
20+
# pylint: disable=cyclic-import
21+
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
1722
except ImportError:
1823
pass
1924

@@ -24,10 +29,10 @@
2429
import adafruit_wiznet5k as wiznet5k
2530

2631
# pylint: disable=invalid-name
27-
_the_interface: Union[wiznet5k.adafruit_wiznet5k.WIZNET5K, None] = None
32+
_the_interface: Optional[WIZNET5K] = None
2833

2934

30-
def set_interface(iface: wiznet5k.adafruit_wiznet5k.WIZNET5K) -> None:
35+
def set_interface(iface: WIZNET5K) -> None:
3136
"""
3237
Helper to set the global internet interface.
3338
@@ -282,12 +287,8 @@ def listen(self, backlog: Optional[Any] = None) -> None:
282287

283288
def accept(
284289
self,
285-
) -> Optional[
286-
Tuple[
287-
wiznet5k.adafruit_wiznet5k_socket.socket,
288-
Tuple[Union[str, bytearray], Union[int, bytearray]],
289-
]
290-
]:
290+
) -> Optional[Tuple[socket, Tuple[Union[str, bytearray], Union[int, bytearray]],]]:
291+
# wiznet5k.adafruit_wiznet5k_socket.socket,
291292
"""
292293
Accept a connection.
293294
@@ -297,7 +298,7 @@ def accept(
297298
socket object to send and receive data on the connection, and address is
298299
the address bound to the socket on the other end of the connection.
299300
300-
:return Union[int, Tuple[int, Tuple[Union[str, bytearray], Union[int, bytearray]]], None]:
301+
:return Optional[Tuple[socket.socket, Tuple[Union[str, bytearray], Union[int, bytearray]]]:
301302
If successful (socket object, (IP address, port)). If errors occur, the IP address
302303
and / or the port may be returned as bytearrays.
303304
"""
@@ -583,7 +584,7 @@ def settimeout(self, value: float) -> None:
583584
raise Exception("Timeout period should be non-negative.")
584585
self._timeout = value
585586

586-
def gettimeout(self) -> Union[float, None]:
587+
def gettimeout(self) -> Optional[float]:
587588
"""
588589
Timeout associated with socket operations.
589590

adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
* Author(s): Matt Costi, Patrick Van Oosterwijck
2828
"""
2929
# pylint: disable=no-name-in-module
30+
# from __future__ import annotations
3031
try:
3132
from typing import Optional, List, Tuple, Dict
33+
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
3234
except ImportError:
3335
pass
3436

@@ -38,10 +40,10 @@
3840
import adafruit_wiznet5k as wiznet5k
3941
import adafruit_wiznet5k.adafruit_wiznet5k_socket as socket
4042

41-
_the_interface = None # pylint: disable=invalid-name
43+
_the_interface: Optional[WIZNET5K] = None # pylint: disable=invalid-name
4244

4345

44-
def set_interface(iface) -> None:
46+
def set_interface(iface: WIZNET5K) -> None:
4547
"""
4648
Helper to set the global internet interface.
4749
@@ -217,10 +219,10 @@ def _get_environ(self, client: socket.socket) -> Dict:
217219
if "content-length" in headers:
218220
env["CONTENT_LENGTH"] = headers.get("content-length")
219221
body = client.recv(int(env["CONTENT_LENGTH"]))
220-
env["wsgi.input"] = io.StringIO(body) # TODO: Is bytes should be str
222+
env["wsgi.input"] = io.StringIO(body)
221223
else:
222224
body = client.recv()
223-
env["wsgi.input"] = io.StringIO(body) # TODO: Is bytes should be str
225+
env["wsgi.input"] = io.StringIO(body)
224226
for name, value in headers.items():
225227
key = "HTTP_" + name.replace("-", "_").upper()
226228
if key in env:

0 commit comments

Comments
 (0)