Skip to content

Commit c7db9e5

Browse files
authored
Merge pull request #3621 from sw23/main
Fixing make stub warnings and mypy issues
2 parents 05d663b + 9f3a1fe commit c7db9e5

File tree

12 files changed

+24
-17
lines changed

12 files changed

+24
-17
lines changed

shared-bindings/canio/CAN.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
//| loopback: bool = False,
5050
//| silent: bool = False,
5151
//| auto_restart: bool = False,
52-
//| ):
52+
//| ) -> None:
5353
//| """A common shared-bus protocol. The rx and tx pins are generally
5454
//| connected to a transceiver which controls the H and L pins on a
5555
//| shared bus.
@@ -171,7 +171,7 @@ STATIC const mp_obj_property_t canio_can_receive_error_count_obj = {
171171
(mp_obj_t)mp_const_none},
172172
};
173173

174-
//| state: State
174+
//| state: BusState
175175
//| """The current state of the bus. (read-only)"""
176176
STATIC mp_obj_t canio_can_state_get(mp_obj_t self_in) {
177177
canio_can_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -291,7 +291,7 @@ STATIC const mp_obj_property_t canio_can_loopback_obj = {
291291
};
292292

293293

294-
//| def send(message: Union[RemoteTransmissionRequest, Message]) -> None:
294+
//| def send(self, message: Union[RemoteTransmissionRequest, Message]) -> None:
295295
//| """Send a message on the bus with the given data and id.
296296
//| If the message could not be sent due to a full fifo or a bus error condition, RuntimeError is raised.
297297
//| """
@@ -352,7 +352,7 @@ STATIC mp_obj_t canio_can_enter(mp_obj_t self_in) {
352352
}
353353
STATIC MP_DEFINE_CONST_FUN_OBJ_1(canio_can_enter_obj, canio_can_enter);
354354

355-
//| def __exit__(self, unused1, unused2, unused3) -> None:
355+
//| def __exit__(self, unused1: Optional[Type[BaseException]], unused2: Optional[BaseException], unused3: Optional[TracebackType]) -> None:
356356
//| """Calls deinit()"""
357357
//| ...
358358
STATIC mp_obj_t canio_can_exit(size_t num_args, const mp_obj_t args[]) {

shared-bindings/canio/Listener.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ STATIC mp_obj_t canio_listener_enter(mp_obj_t self_in) {
123123
}
124124
STATIC MP_DEFINE_CONST_FUN_OBJ_1(canio_listener_enter_obj, canio_listener_enter);
125125

126-
//| def __exit__(self, unused1, unused2, unused3) -> None:
126+
//| def __exit__(self, unused1: Optional[Type[BaseException]], unused2: Optional[BaseException], unused3: Optional[TracebackType]) -> None:
127127
//| """Calls deinit()"""
128128
//| ...
129129
STATIC mp_obj_t canio_listener_exit(size_t num_args, const mp_obj_t args[]) {

shared-bindings/canio/Match.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//| """Describe CAN bus messages to match"""
3434
//|
3535
//|
36-
//| def __init__(self, id: int, *, mask: Optional[int] = None, extended: bool = False):
36+
//| def __init__(self, id: int, *, mask: Optional[int] = None, extended: bool = False) -> None:
3737
//| """Construct a Match with the given properties.
3838
//|
3939
//| If mask is not None, then the filter is for any id which matches all

shared-bindings/canio/Message.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "py/runtime.h"
3232

3333
//| class Message:
34-
//| def __init__(self, id: int, data: bytes, *, extended: bool = False):
34+
//| def __init__(self, id: int, data: bytes, *, extended: bool = False) -> None:
3535
//| """Construct a Message to send on a CAN bus.
3636
//|
3737
//| :param int id: The numeric ID of the message

shared-bindings/canio/RemoteTransmissionRequest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "py/runtime.h"
3232

3333
//| class RemoteTransmissionRequest:
34-
//| def __init__(self, id: int, length: int, *, extended: bool = False):
34+
//| def __init__(self, id: int, length: int, *, extended: bool = False) -> None:
3535
//| """Construct a RemoteTransmissionRequest to send on a CAN bus.
3636
//|
3737
//| :param int id: The numeric ID of the requested message

shared-bindings/displayio/Bitmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
172172
return mp_const_none;
173173
}
174174

175-
//| def blit(self, x: int, y: int, source_bitmap: bitmap, *, x1: int, y1: int, x2: int, y2: int, skip_index: int) -> None:
175+
//| def blit(self, x: int, y: int, source_bitmap: Bitmap, *, x1: int, y1: int, x2: int, y2: int, skip_index: int) -> None:
176176
//| """Inserts the source_bitmap region defined by rectangular boundaries
177177
//| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location.
178178
//|
@@ -274,7 +274,7 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg
274274
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_bitmap_blit_obj, 4, displayio_bitmap_obj_blit);
275275
// `displayio_bitmap_obj_blit` requires at least 4 arguments
276276

277-
//| def fill(self, value: Any) -> None:
277+
//| def fill(self, value: int) -> None:
278278
//| """Fills the bitmap with the supplied palette index value."""
279279
//| ...
280280
//|

shared-bindings/displayio/Display.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "shared-module/displayio/__init__.h"
4040
#include "supervisor/shared/translate.h"
4141

42-
//| _DisplayBus = Union[FourWire, ParallelBus, I2CDisplay]
42+
//| _DisplayBus = Union['FourWire', 'ParallelBus', 'I2CDisplay']
4343
//| """:py:class:`FourWire`, :py:class:`ParallelBus` or :py:class:`I2CDisplay`"""
4444
//|
4545

shared-bindings/socketpool/Socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ STATIC mp_obj_t socketpool_socket_close(mp_obj_t self_in) {
161161
}
162162
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socketpool_socket_close_obj, socketpool_socket_close);
163163

164-
//| def connect(self, address: tuple) -> None:
164+
//| def connect(self, address: Tuple[str, int]) -> None:
165165
//| """Connect a socket to a remote address
166166
//|
167167
//| :param ~tuple address: tuple of (remote_address, remote_port)"""

shared-bindings/socketpool/SocketPool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ STATIC mp_obj_t socketpool_socketpool_socket(size_t n_args, const mp_obj_t *pos_
8282
}
8383
MP_DEFINE_CONST_FUN_OBJ_KW(socketpool_socketpool_socket_obj, 1, socketpool_socketpool_socket);
8484

85-
//| def getaddrinfo(host: str, port: int, family: int = 0, type: int = 0, proto: int = 0, flags: int = 0) -> tuple:
85+
//| def getaddrinfo(host: str, port: int, family: int = 0, type: int = 0, proto: int = 0, flags: int = 0) -> Tuple[int, int, int, str, Tuple[str, int]]:
8686
//| """Gets the address information for a hostname and port
8787
//|
8888
//| Returns the appropriate family, socket type, socket protocol and

shared-bindings/ssl/SSLContext.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ STATIC mp_obj_t ssl_sslcontext_make_new(const mp_obj_type_t *type, size_t n_args
5151
return MP_OBJ_FROM_PTR(s);
5252
}
5353

54-
//| def wrap_socket(sock: socketpool.Socket, *, server_side: bool = False, server_hostname: str = None) -> socketpool.Socket:
54+
//| def wrap_socket(sock: socketpool.Socket, *, server_side: bool = False, server_hostname: Optional[str] = None) -> socketpool.Socket:
5555
//| """Wraps the socket into a socket-compatible class that handles SSL negotiation.
5656
//| The socket must be of type SOCK_STREAM."""
5757
//| ...

shared-bindings/wifi/Radio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const mp_obj_property_t wifi_radio_mac_address_obj = {
7979
};
8080

8181

82-
//| def start_scanning_networks(self, *, start_channel=1, stop_channel=11) -> Iterable[Network]:
82+
//| def start_scanning_networks(self, *, start_channel: int = 1, stop_channel: int = 11) -> Iterable[Network]:
8383
//| """Scans for available wifi networks over the given channel range. Make sure the channels are allowed in your country."""
8484
//| ...
8585
//|
@@ -283,7 +283,7 @@ const mp_obj_property_t wifi_radio_ap_info_obj = {
283283
(mp_obj_t)&mp_const_none_obj },
284284
};
285285

286-
//| def ping(self, ip, *, timeout: float = 0.5) -> float:
286+
//| def ping(self, ip: ipaddress.IPv4Address, *, timeout: Optional[float] = 0.5) -> float:
287287
//| """Ping an IP to test connectivity. Returns echo time in seconds.
288288
//| Returns None when it times out."""
289289
//| ...

tools/extract_pyi.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818

1919
IMPORTS_IGNORE = frozenset({'int', 'float', 'bool', 'str', 'bytes', 'tuple', 'list', 'set', 'dict', 'bytearray', 'slice', 'file', 'buffer', 'range', 'array', 'struct_time'})
20-
IMPORTS_TYPING = frozenset({'Any', 'Optional', 'Union', 'Tuple', 'List', 'Sequence', 'NamedTuple', 'Iterable', 'Iterator', 'Callable', 'AnyStr', 'overload'})
20+
IMPORTS_TYPING = frozenset({'Any', 'Optional', 'Union', 'Tuple', 'List', 'Sequence', 'NamedTuple', 'Iterable', 'Iterator', 'Callable', 'AnyStr', 'overload', 'Type'})
21+
IMPORTS_TYPES = frozenset({'TracebackType'})
2122
CPY_TYPING = frozenset({'ReadableBuffer', 'WriteableBuffer', 'AudioSample', 'FrameBuffer'})
2223

2324

@@ -63,6 +64,7 @@ def find_stub_issues(tree):
6364
def extract_imports(tree):
6465
modules = set()
6566
typing = set()
67+
types = set()
6668
cpy_typing = set()
6769

6870
def collect_annotations(anno_tree):
@@ -74,6 +76,8 @@ def collect_annotations(anno_tree):
7476
continue
7577
elif node.id in IMPORTS_TYPING:
7678
typing.add(node.id)
79+
elif node.id in IMPORTS_TYPES:
80+
types.add(node.id)
7781
elif node.id in CPY_TYPING:
7882
cpy_typing.add(node.id)
7983
elif isinstance(node, ast.Attribute):
@@ -94,6 +98,7 @@ def collect_annotations(anno_tree):
9498
return {
9599
"modules": sorted(modules),
96100
"typing": sorted(typing),
101+
"types": sorted(types),
97102
"cpy_typing": sorted(cpy_typing),
98103
}
99104

@@ -181,6 +186,8 @@ def convert_folder(top_level, stub_directory):
181186
# Add import statements
182187
imports = extract_imports(tree)
183188
import_lines = ["from __future__ import annotations"]
189+
if imports["types"]:
190+
import_lines.append("from types import " + ", ".join(imports["types"]))
184191
if imports["typing"]:
185192
import_lines.append("from typing import " + ", ".join(imports["typing"]))
186193
if imports["cpy_typing"]:

0 commit comments

Comments
 (0)