8000 Use a function to raise ZeroDivisionError, consistent string · jepler/circuitpython@0e19fbb · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e19fbb

Browse files
committed
Use a function to raise ZeroDivisionError, consistent string
1 parent 2b01c13 commit 0e19fbb

File tree

8 files changed

+15
-60
lines changed

8 files changed

+15
-60
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ msgstr ""
118118
msgid "%q is %q"
119119
msgstr ""
120120

121-
#: py/argcheck.c
121+
#: py/argcheck.c shared-bindings/usb_hid/Device.c
122122
msgid "%q length must be %d"
123123
msgstr ""
124124

@@ -130,14 +130,10 @@ msgstr ""
130130
msgid "%q length must be <= %d"
131131
msgstr ""
132132

133-
#: py/argcheck.c
133+
#: py/argcheck.c shared-bindings/busio/I2C.c
134134
msgid "%q length must be >= %d"
135135
msgstr ""
136136

137-
#: shared-bindings/busio/I2C.c
138-
msgid "%q length must be >= 1"
139-
msgstr ""
140-
141137
#: py/argcheck.c
142138
msgid "%q must be %d"
143139
msgstr ""
@@ -163,14 +159,6 @@ msgstr ""
163159
msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'"
164160
msgstr ""
165161

166-
#: py/argcheck.c
167-
msgid "%q must be a string"
168-
msgstr ""
169-
170-
#: py/argcheck.c
171-
msgid "%q must be an int"
172-
msgstr ""
173-
174162
#: py/argcheck.c py/obj.c
175163
msgid "%q must be of type %q"
176164
msgstr ""
@@ -201,10 +189,6 @@ msgstr ""
201189
msgid "%q pin invalid"
202190
msgstr ""
203191

204-
#: shared-bindings/usb_hid/Device.c
205-
msgid "%q with a report ID of 0 must be of length 1"
206-
msgstr ""
207-
208192
#: py/bc.c py/objnamedtuple.c
209193
msgid "%q() takes %d positional arguments but %d were given"
210194
msgstr ""
@@ -511,10 +495,6 @@ msgstr ""
511495
msgid "Array values should be single bytes."
512496
msgstr ""
513497

514-
#: shared-bindings/microcontroller/Pin.c
515-
msgid "At most %d %q may be specified (not %d)"
516-
msgstr ""
517-
518498
#: shared-module/memorymonitor/AllocationAlarm.c
519499
#, c-format
520500
msgid "Attempt to allocate %d blocks"
@@ -1260,10 +1240,6 @@ msgstr ""
12601240
msgid "Invalid multicast MAC address"
12611241
msgstr ""
12621242

1263-
#: shared-bindings/busio/UART.c
1264-
msgid "Invalid pins"
1265-
msgstr ""
1266-
12671243
#: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c
12681244
msgid "Invalid size"
12691245
msgstr ""
@@ -1501,11 +1477,6 @@ msgstr ""
15011477
msgid "No long integer support"
15021478
msgstr ""
15031479

1504-
#: shared-module/usb_hid/__init__.c
1505-
#, c-format
1506-
msgid "No more than %d HID devices allowed"
1507-
msgstr ""
1508-
15091480
#: shared-bindings/wifi/Radio.c
15101481
msgid "No network with that ssid"
15111482
msgstr ""
@@ -2545,10 +2516,6 @@ msgstr ""
25452516
msgid "buffer too small for requested bytes"
25462517
msgstr ""
25472518

2548-
#: shared-bindings/adafruit_pixelbuf/PixelBuf.c
2549-
msgid "byteorder is not a string"
2550-
msgstr ""
2551-
25522519
#: py/objarray.c
25532520
msgid "bytes length not a multiple of item size"
25542521
msgstr ""
@@ -2590,14 +2557,10 @@ msgstr ""
25902557
msgid "can't cancel self"
25912558
msgstr ""
25922559

2593-
#: py/obj.c py/objint.c shared-module/adafruit_pixelbuf/PixelBuf.c
2560+
#: py/obj.c py/objint.c py/runtime.c shared-module/adafruit_pixelbuf/PixelBuf.c
25942561
msgid "can't convert %q to %q"
25952562
msgstr ""
25962563

2597-
#: py/runtime.c
2598-
msgid "can't convert %q to int"
2599-
msgstr ""
2600-
26012564
#: py/obj.c
26022565
#, c-format
26032566
msgid "can't convert %s to complex"
@@ -2781,10 +2744,6 @@ msgstr ""
27812744
msgid "comparison of int and uint"
27822745
msgstr ""
27832746

2784-
#: py/objcomplex.c
2785-
msgid "complex division by zero"
2786-
msgstr ""
2787-
27882747
#: py/objfloat.c py/parsenum.c
27892748
msgid "complex values not supported"
27902749
msgstr ""
@@ -2887,12 +2846,7 @@ msgstr ""
28872846
msgid "div/mod not implemented for uint"
28882847
msgstr ""
28892848

2890-
#: py/objfloat.c py/objint_mpz.c
2891-
msgid "divide by zero"
2892-
msgstr ""
2893-
2894-
#: py/modmath.c py/objint_longlong.c py/runtime.c
2895-
#: shared-bindings/math/__init__.c
2849+
#: py/runtime.c shared-bindings/math/__init__.c
28962850
msgid "division by zero"
28972851
msgstr ""
28982852

@@ -4043,10 +3997,6 @@ msgstr ""
40433997
msgid "syntax error in uctypes descriptor"
40443998
msgstr ""
40453999

4046-
#: shared-bindings/time/__init__.c
4047-
msgid "time.struct_time() takes a 9-sequence"
4048-
msgstr ""
4049-
40504000
#: ports/atmel-samd/common-hal/watchdog/WatchDogTimer.c
40514001
#: ports/espressif/common-hal/watchdog/WatchDogTimer.c
40524002
#: ports/nrf/common-hal/watchdog/WatchDogTimer.c

py/modmath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) {
254254
if (base <= (mp_float_t)0.0) {
255255
math_error();
256256
} else if (base == (mp_float_t)1.0) {
257-
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero"));
257+
mp_raise_ZeroDivisionError();
258258
}
259259
return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base));
260260
}

py/objcomplex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_binary_op_t op, mp_float_t lhs_real, mp_flo
217217
case MP_BINARY_OP_INPLACE_TRUE_DIVIDE:
218218
if (rhs_imag == 0) {
219219
if (rhs_real == 0) {
220-
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("complex division by zero"));
220+
mp_raise_ZeroDivisionError();
221221
}
222222
lhs_real /= rhs_real;
223223
lhs_imag /= rhs_real;

py/objfloat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t
266266
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
267267
if (rhs_val == 0) {
268268
zero_division_error:
269-
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("divide by zero"));
269+
mp_raise_ZeroDivisionError();
270270
}
271271
// Python specs require that x == (x//y)*y + (x%y) so we must
272272
// call divmod to compute the correct floor division, which

py/objint_longlong.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
236236
}
237237

238238
zero_division:
239-
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero"));
239+
mp_raise_ZeroDivisionError();
240240
}
241241

242242
mp_obj_t mp_obj_new_int(mp_int_t value) {

py/objint_mpz.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
244244
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE: {
245245
if (mpz_is_zero(zrhs)) {
246246
zero_division_error:
247-
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("divide by zero"));
247+
mp_raise_ZeroDivisionError();
248248
}
249249
mpz_t rem;
250250
mpz_init_zero(&rem);

py/runtime.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ mp_obj_t MICROPY_WRAP_MP_BINARY_OP(mp_binary_op)(mp_binary_op_t op, mp_obj_t lhs
631631
#endif
632632

633633
zero_division:
634-
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero"));
634+
mp_raise_ZeroDivisionError();
635635
}
636636

637637
mp_obj_t mp_call_function_0(mp_obj_t fun) {
@@ -1765,3 +1765,7 @@ NORETURN void mp_raise_recursion_depth(void) {
17651765
mp_raise_RuntimeError(MP_ERROR_TEXT("maximum recursion depth exceeded"));
17661766
}
17671767
#endif
1768+
1769+
NORETURN void mp_raise_ZeroDivisionError(void) {
1770+
mp_raise_msg(&mp_type_ZeroDivisionError, MP_ERROR_TEXT("division by zero"));
1771+
}

py/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);
226226
NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...);
227227
NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...);
228228
NORETURN void mp_raise_recursion_depth(void);
229+
NORETURN void mp_raise_ZeroDivisionError(void);
229230
#endif
230231

231232
#if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG

0 commit comments

Comments
 (0)
0