Skip to content

Commit 6d2114b

Browse files
authored
Merge pull request #5439 from dhalbert/fix-min-pos-args
Fix n_args_min on many MP_DEFINE_CONST_FUN_OBJ_KW()
2 parents e174de8 + 431e784 commit 6d2114b

File tree

22 files changed

+238
-173
lines changed

22 files changed

+238
-173
lines changed

shared-bindings/_bleio/Adapter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ STATIC mp_obj_t bleio_adapter_start_advertising(mp_uint_t n_args, const mp_obj_t
271271

272272
return mp_const_none;
273273
}
274-
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_start_advertising_obj, 2, bleio_adapter_start_advertising);
274+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_start_advertising_obj, 1, bleio_adapter_start_advertising);
275275

276276
//| def stop_advertising(self) -> None:
277277
//| """Stop sending advertising packets."""
@@ -456,7 +456,7 @@ STATIC mp_obj_t bleio_adapter_connect(mp_uint_t n_args, const mp_obj_t *pos_args
456456

457457
return common_hal_bleio_adapter_connect(self, address, timeout);
458458
}
459-
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_connect_obj, 2, bleio_adapter_connect);
459+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_connect_obj, 1, bleio_adapter_connect);
460460

461461
//| def erase_bonding(self) -> None:
462462
//| """Erase all bonding information stored in flash memory."""

shared-bindings/_bleio/Characteristic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ STATIC mp_obj_t bleio_characteristic_add_to_service(size_t n_args, const mp_obj_
156156

157157
return MP_OBJ_FROM_PTR(characteristic);
158158
}
159-
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_characteristic_add_to_service_fun_obj, 3, bleio_characteristic_add_to_service);
159+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_characteristic_add_to_service_fun_obj, 1, bleio_characteristic_add_to_service);
160160
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(bleio_characteristic_add_to_service_obj, MP_ROM_PTR(&bleio_characteristic_add_to_service_fun_obj));
161161

162162

shared-bindings/_bleio/Descriptor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ STATIC mp_obj_t bleio_descriptor_add_to_characteristic(size_t n_args, const mp_o
136136

137137
return MP_OBJ_FROM_PTR(descriptor);
138138
}
139-
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_descriptor_add_to_characteristic_fun_obj, 3, bleio_descriptor_add_to_characteristic);
139+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_descriptor_add_to_characteristic_fun_obj, 1, bleio_descriptor_add_to_characteristic);
140140
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(bleio_descriptor_add_to_characteristic_obj, MP_ROM_PTR(&bleio_descriptor_add_to_characteristic_fun_obj));
141141

142142
//| uuid: UUID

shared-bindings/_bleio/ScanEntry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ STATIC mp_obj_t bleio_scanentry_matches(mp_uint_t n_args, const mp_obj_t *pos_ar
7272
mp_get_buffer_raise(args[ARG_prefixes].u_obj, &bufinfo, MP_BUFFER_READ);
7373
return mp_obj_new_bool(common_hal_bleio_scanentry_matches(self, bufinfo.buf, bufinfo.len, match_all));
7474
}
75-
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanentry_matches_obj, 2, bleio_scanentry_matches);
75+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanentry_matches_obj, 1, bleio_scanentry_matches);
7676

7777
//| address: Address
7878
//| """The address of the device (read-only), of type `_bleio.Address`."""

shared-bindings/_bleio/UUID.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ STATIC mp_obj_t bleio_uuid_pack_into(mp_uint_t n_args, const mp_obj_t *pos_args,
214214
common_hal_bleio_uuid_pack_into(self, bufinfo.buf + offset);
215215
return mp_const_none;
216216
}
217-
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_uuid_pack_into_obj, 2, bleio_uuid_pack_into);
217+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_uuid_pack_into_obj, 1, bleio_uuid_pack_into);
218218

219219
STATIC const mp_rom_map_elem_t bleio_uuid_locals_dict_table[] = {
220220
{ MP_ROM_QSTR(MP_QSTR_uuid16), MP_ROM_PTR(&bleio_uuid_uuid16_obj) },

shared-bindings/adafruit_bus_device/I2CDevice.c

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
//| device.readinto(bytes_read)
6464
//| # A second transaction
6565
//| with device:
66-
//| device.write(bytes_read)"""
66+
//| device.write(bytes_read)
67+
//| """
6768
//| ...
6869
//|
6970
STATIC mp_obj_t adafruit_bus_device_i2cdevice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@@ -109,16 +110,18 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_obj___exit__(size_t n_args, const
109110
}
110111
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(adafruit_bus_device_i2cdevice___exit___obj, 4, 4, adafruit_bus_device_i2cdevice_obj___exit__);
111112

112-
//| def readinto(self, buf: WriteableBuffer, *, start: int = 0, end: Optional[int] = None) -> None:
113-
//| """Read into ``buf`` from the device. The number of bytes read will be the
114-
//| length of ``buf``.
113+
//| import sys
114+
//| def readinto(self, buffer: WriteableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
115+
//| """Read into ``buffer`` from the device.
116+
//|
115117
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
116-
//| as if ``buf[start:end]``. This will not cause an allocation like
117-
//| ``buf[start:end]`` will so it saves memory.
118+
//| as if ``buffer[start:end]`` were passed.
119+
//| The number of bytes read will be the length of ``buffer[start:end]``.
118120
//|
119-
//| :param bytearray buf: buffer to write into
120-
//| :param int start: Index to start writing at
121-
//| :param int end: Index to write up to but not include; if None, use ``len(buf)``"""
121+
//| :param WriteableBuffer buffer: read bytes into this buffer
122+
//| :param int start: beginning of buffer slice
123+
//| :param int end: end of buffer slice; if not specified, use ``len(buffer)``
124+
//| """
122125
//| ...
123126
//|
124127
STATIC mp_obj_t adafruit_bus_device_i2cdevice_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@@ -152,17 +155,19 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_readinto(size_t n_args, const mp_o
152155

153156
return mp_const_none;
154157
}
155-
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_readinto_obj, 2, adafruit_bus_device_i2cdevice_readinto);
158+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_readinto_obj, 1, adafruit_bus_device_i2cdevice_readinto);
156159

157-
//| def write(self, buf: ReadableBuffer, *, start: int = 0, end: Optional[int] = None) -> None:
160+
//| import sys
161+
//| def write(self, buffer: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
158162
//| """Write the bytes from ``buffer`` to the device, then transmit a stop bit.
163+
//|
159164
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
160-
//| as if ``buffer[start:end]``. This will not cause an allocation like
161-
//| ``buffer[start:end]`` will so it saves memory.
165+
//| as if ``buffer[start:end]`` were passed, but without copying the data.
166+
//| The number of bytes written will be the length of ``buffer[start:end]``.
162167
//|
163-
//| :param bytearray buf: buffer containing the bytes to write
164-
//| :param int start: Index to start writing from
165-
//| :param int end: Index to read up to but not include; if None, use ``len(buf)``
168+
//| :param ReadableBuffer buffer: write out bytes from this buffer
169+
//| :param int start: beginning of buffer slice
170+
//| :param int end: end of buffer slice; if not specified, use ``len(buffer)``
166171
//| """
167172
//| ...
168173
//|
@@ -196,28 +201,28 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_write(size_t n_args, const mp_obj_
196201

197202
return mp_const_none;
198203
}
199-
MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_obj, 2, adafruit_bus_device_i2cdevice_write);
204+
MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_obj, 1, adafruit_bus_device_i2cdevice_write);
200205

201206

202-
//| def write_then_readinto(self, out_buffer: WriteableBuffer, in_buffer: ReadableBuffer, *, out_start: int = 0, out_end: Optional[int] = None, in_start: int = 0, in_end: Optional[int] = None) -> None:
207+
//| import sys
208+
//| def write_then_readinto(self, out_buffer: ReadableBuffer, in_buffer: WriteableBuffer, *, out_start: int = 0, out_end: int = sys.maxsize, in_start: int = 0, in_end: int = sys.maxsize) -> None:
203209
//| """Write the bytes from ``out_buffer`` to the device, then immediately
204-
//| reads into ``in_buffer`` from the device. The number of bytes read
205-
//| will be the length of ``in_buffer``.
206-
//| If ``out_start`` or ``out_end`` is provided, then the output buffer
207-
//| will be sliced as if ``out_buffer[out_start:out_end]``. This will
208-
//| not cause an allocation like ``buffer[out_start:out_end]`` will so
209-
//| it saves memory.
210-
//| If ``in_start`` or ``in_end`` is provided, then the input buffer
211-
//| will be sliced as if ``in_buffer[in_start:in_end]``. This will not
212-
//| cause an allocation like ``in_buffer[in_start:in_end]`` will so
213-
//| it saves memory.
210+
//| reads into ``in_buffer`` from the device.
211+
//|
212+
//| If ``out_start`` or ``out_end`` is provided, then the buffer will be sliced
213+
//| as if ``out_buffer[out_start:out_end]`` were passed, but without copying the data.
214+
//| The number of bytes written will be the length of ``out_buffer[out_start:out_end]``.
215+
//|
216+
//| If ``in_start`` or ``in_end`` is provided, then the input buffer will be sliced
217+
//| as if ``in_buffer[in_start:in_end]`` were passed,
218+
//| The number of bytes read will be the length of ``out_buffer[in_start:in_end]``.
214219
//|
215-
//| :param bytearray out_buffer: buffer containing the bytes to write
216-
//| :param bytearray in_buffer: buffer containing the bytes to read into
217-
//| :param int out_start: Index to start writing from
218-
//| :param int out_end: Index to read up to but not include; if None, use ``len(out_buffer)``
219-
//| :param int in_start: Index to start writing at
220-
//| :param int in_end: Index to write up to but not include; if None, use ``len(in_buffer)``
220+
//| :param ReadableBuffer out_buffer: write out bytes from this buffer
221+
//| :param WriteableBuffer in_buffer: read bytes into this buffer
222+
//| :param int out_start: beginning of ``out_buffer`` slice
223+
//| :param int out_end: end of ``out_buffer`` slice; if not specified, use ``len(out_buffer)``
224+
//| :param int in_start: beginning of ``in_buffer`` slice
225+
//| :param int in_end: end of ``in_buffer slice``; if not specified, use ``len(in_buffer)``
221226
//| """
222227
//| ...
223228
//|
@@ -263,7 +268,7 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_write_then_readinto(size_t n_args,
263268

264269
return mp_const_none;
265270
}
266-
MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_then_readinto_obj, 3, adafruit_bus_device_i2cdevice_write_then_readinto);
271+
MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_then_readinto_obj, 1, adafruit_bus_device_i2cdevice_write_then_readinto);
267272

268273
STATIC const mp_rom_map_elem_t adafruit_bus_device_i2cdevice_locals_dict_table[] = {
269274
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&adafruit_bus_device_i2cdevice___enter___obj) },

shared-bindings/bitbangio/I2C.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ STATIC mp_obj_t bitbangio_i2c_obj_unlock(mp_obj_t self_in) {
165165
}
166166
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_unlock_obj, bitbangio_i2c_obj_unlock);
167167

168-
//| def readfrom_into(self, address: int, buffer: WriteableBuffer, *, start: int = 0, end: Optional[int] = None) -> None:
168+
//| import sys
169+
//| def readfrom_into(self, address: int, buffer: WriteableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
169170
//| """Read into ``buffer`` from the device selected by ``address``.
170171
//| The number of bytes read will be the length of ``buffer``.
171172
//| At least one byte must be read.
@@ -175,7 +176,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_unlock_obj, bitbangio_i2c_obj_unlock);
175176
//| ``buf[start:end]`` will so it saves memory.
176177
//|
177178
//| :param int address: 7-bit device address
178-
//| :param ~_typing.WriteableBuffer buffer: buffer to write into
179+
//| :param WriteableBuffer buffer: buffer to write into
179180
//| :param int start: Index to start writing at
180181
//| :param int end: Index to write up to but not include"""
181182
//| ...
@@ -215,24 +216,26 @@ STATIC mp_obj_t bitbangio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_a
215216
args[ARG_end].u_int);
216217
return mp_const_none;
217218
}
218-
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 3, bitbangio_i2c_readfrom_into);
219+
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 1, bitbangio_i2c_readfrom_into);
219220

220-
//| def writeto(self, address: int, buffer: ReadableBuffer, *, start: int = 0, end: Optional[int] = None) -> None:
221+
//| import sys
222+
//| def writeto(self, address: int, buffer: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
221223
//| """Write the bytes from ``buffer`` to the device selected by ``address`` and then transmits a
222224
//| stop bit. Use `writeto_then_readfrom` when needing a write, no stop and repeated start
223225
//| before a read.
224226
//|
225227
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
226-
//| as if ``buffer[start:end]``. This will not cause an allocation like
227-
//| ``buffer[start:end]`` will so it saves memory.
228+
//| as if ``buffer[start:end]`` were passed, but without copying the data.
229+
//| The number of bytes written will be the length of ``buffer[start:end]``.
228230
//|
229231
//| Writing a buffer or slice of length zero is permitted, as it can be used
230232
//| to poll for the existence of a device.
231233
//|
232234
//| :param int address: 7-bit device address
233-
//| :param ~_typing.ReadableBuffer buffer: buffer containing the bytes to write
234-
//| :param int start: Index to start writing from
235-
//| :param int end: Index to read up to but not include"""
235+
//| :param ReadableBuffer buffer: buffer containing the bytes to write
236+
//| :param int start: beginning of buffer slice
237+
//| :param int end: end of buffer slice; if not specified, use ``len(buffer)``
238+
//| """
236239
//| ...
237240
//|
238241
// Shared arg parsing for writeto and writeto_then_readfrom.
@@ -274,22 +277,29 @@ STATIC mp_obj_t bitbangio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, m
274277
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_writeto);
275278

276279

277-
//| def writeto_then_readfrom(self, address: int, out_buffer: ReadableBuffer, in_buffer: ReadableBuffer, *, out_start: int = 0, out_end: Optional[int] = None, in_start: int = 0, in_end: Optional[int] = None) -> None:
280+
//| import sys
281+
//| def writeto_then_readfrom(self, address: int, out_buffer: ReadableBuffer, in_buffer: ReadableBuffer, *, out_start: int = 0, out_end: int = sys.maxsize, in_start: int = 0, in_end: int = sys.maxsize) -> None:
278282
//| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop
279283
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
280284
//| ``in_buffer`` can be the same buffer because they are used sequentially.
281285
//|
282-
//| If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced
283-
//| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``
284-
//| will so it saves memory.
286+
//| If ``out_start`` or ``out_end`` is provided, then the buffer will be sliced
287+
//| as if ``out_buffer[out_start:out_end]`` were passed, but without copying the data.
288+
//| The number of bytes written will be the length of ``out_buffer[start:end]``.
285289
//|
290+
//| If ``in_start`` or ``in_end`` is provided, then the input buffer will be sliced
291+
//| as if ``in_buffer[in_start:in_end]`` were passed,
292+
//| The number of bytes read will be the length of ``out_buffer[in_start:in_end]``.
293+
286294
//| :param int address: 7-bit device address
287295
//| :param ~_typing.ReadableBuffer out_buffer: buffer containing the bytes to write
288296
//| :param ~_typing.WriteableBuffer in_buffer: buffer to write into
289-
//| :param int out_start: Index to start writing from
290-
//| :param int out_end: Index to read up to but not include. Defaults to ``len(buffer)``
291-
//| :param int in_start: Index to start writing at
292-
//| :param int in_end: Index to write up to but not include. Defaults to ``len(buffer)``"""
297+
//| :param int out_start: beginning of ``out_buffer`` slice
298+
//| :param int out_end: end of ``out_buffer`` slice; if not specified, use ``len(out_buffer)``
299+
//| :param int in_start: beginning of ``in_buffer`` slice
300+
//| :param int in_end: end of ``in_buffer slice``; if not specified, use ``len(in_buffer)``
301+
//| """
302+
//| ...
293303
//|
294304
STATIC mp_obj_t bitbangio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
295305
enum { ARG_address, ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
@@ -315,7 +325,7 @@ STATIC mp_obj_t bitbangio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_
315325

316326
return mp_const_none;
317327
}
318-
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_then_readfrom_obj, 3, bitbangio_i2c_writeto_then_readfrom);
328+
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_then_readfrom_obj, 1, bitbangio_i2c_writeto_then_readfrom);
319329

320330
STATIC const mp_rom_map_elem_t bitbangio_i2c_locals_dict_table[] = {
321331
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&bitbangio_i2c_deinit_obj) },

0 commit comments

Comments
 (0)