Skip to content

Commit 9116470

Browse files
committed
Added type hints to socket
1 parent 71ec419 commit 9116470

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

shared-bindings/socket/__init__.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ STATIC void socket_select_nic(mod_network_socket_obj_t *self, const byte *ip) {
9393
}
9494
}
9595

96-
//| def bind(self, address: tuple) -> Any:
96+
//| def bind(self, address: tuple) -> None:
9797
//| """Bind a socket to an address
9898
//|
9999
//| :param ~tuple address: tuple of (remote_address, remote_port)"""
@@ -120,7 +120,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
120120
}
121121
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind);
122122

123-
//| def listen(self, backlog: int) -> Any:
123+
//| def listen(self, backlog: int) -> None:
124124
//| """Set socket to listen for incoming connections
125125
//|
126126
//| :param ~int backlog: length of backlog queue for waiting connetions"""
@@ -145,7 +145,7 @@ STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) {
145145
}
146146
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen);
147147

148-
//| def accept(self) -> Any:
148+
//| def accept(self) -> tuple:
149149
//| """Accept a connection on a listening socket of type SOCK_STREAM,
150150
//| creating a new socket of type SOCK_STREAM.
151151
//| Returns a tuple of (new_socket, remote_address)"""
@@ -182,7 +182,7 @@ STATIC mp_obj_t socket_accept(mp_obj_t self_in) {
182182
}
183183
STATIC MP_DEFINE_CONST_FUN_OBJ_1(socket_accept_obj, socket_accept);
184184

185-
//| def connect(self, address: tuple) -> Any:
185+
//| def connect(self, address: tuple) -> None:
186186
//| """Connect a socket to a remote address
187187
//|
188188
//| :param ~tuple address: tuple of (remote_address, remote_port)"""
@@ -209,7 +209,7 @@ STATIC mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
209209
}
210210
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_connect_obj, socket_connect);
211211

212-
//| def send(self, bytes: bytes) -> Any:
212+
//| def send(self, bytes: bytes) -> int:
213213
//| """Send some bytes to the connected remote address.
214214
//| Suits sockets of type SOCK_STREAM
215215
//|
@@ -246,7 +246,7 @@ STATIC mp_int_t _socket_recv_into(mod_network_socket_obj_t *sock, byte *buf, mp_
246246
}
247247

248248

249-
//| def recv_into(self, buffer: bytearray, bufsize: int) -> Any:
249+
//| def recv_into(self, buffer: WriteableBuffer, bufsize: int) -> int:
250250
//| """Reads some bytes from the connected remote address, writing
251251
//| into the provided buffer. If bufsize <= len(buffer) is given,
252252
//| a maximum of bufsize bytes will be read into the buffer. If no
@@ -282,7 +282,7 @@ STATIC mp_obj_t socket_recv_into(size_t n_args, const mp_obj_t *args) {
282282
}
283283
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_recv_into_obj, 2, 3, socket_recv_into);
284284

285-
//| def recv(self, bufsize: int) -> Any:
285+
//| def recv(self, bufsize: int) -> bytes:
286286
//| """Reads some bytes from the connected remote address.
287287
//| Suits sockets of type SOCK_STREAM
288288
//| Returns a bytes() of length <= bufsize
@@ -309,7 +309,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
309309
}
310310
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recv_obj, socket_recv);
311311

312-
//| def sendto(self, bytes: bytes, address: tuple) -> Any:
312+
//| def sendto(self, bytes: bytes, address: tuple) -> int:
313313
//| """Send some bytes to a specific address.
314314
//| Suits sockets of type SOCK_DGRAM
315315
//|
@@ -343,7 +343,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
343343
}
344344
STATIC MP_DEFINE_CONST_FUN_OBJ_3(socket_sendto_obj, socket_sendto);
345345

346-
//| def recvfrom(self, bufsize: int) -> Any:
346+
//| def recvfrom(self, bufsize: int) -> Tuple[bytes, tuple]:
347347
//| """Reads some bytes from the connected remote address.
348348
//| Suits sockets of type SOCK_STREAM
349349
//|
@@ -382,7 +382,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
382382
}
383383
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_recvfrom_obj, socket_recvfrom);
384384

385-
//| def setsockopt(self, level: Any, optname: Any, value: Any) -> Any:
385+
//| def setsockopt(self, level: int, optname: int, value: int) -> None:
386386
//| """Sets socket options"""
387387
//| ...
388388
//|
@@ -416,7 +416,7 @@ STATIC mp_obj_t socket_setsockopt(size_t n_args, const mp_obj_t *args) {
416416
}
417417
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_setsockopt_obj, 4, 4, socket_setsockopt);
418418

419-
//| def settimeout(self, value: int) -> Any:
419+
//| def settimeout(self, value: int) -> None:
420420
//| """Set the timeout value for this socket.
421421
//|
422422
//| :param ~int value: timeout in seconds. 0 means non-blocking. None means block indefinitely."""
@@ -447,7 +447,7 @@ STATIC mp_obj_t socket_settimeout(mp_obj_t self_in, mp_obj_t timeout_in) {
447447
}
448448
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_settimeout_obj, socket_settimeout);
449449

450-
//| def setblocking(self, flag: bool) -> Any:
450+
//| def setblocking(self, flag: bool) -> Optional[int]:
451451
//| """Set the blocking behaviour of this socket.
452452
//|
453453
//| :param ~bool flag: False means non-blocking, True means block indefinitely."""

0 commit comments

Comments
 (0)