summaryrefslogtreecommitdiff
path: root/py/objnamedtuple.c
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-11-19 16:18:52 -0600
committerJeff Epler <jepler@gmail.com>2020-11-19 16:18:52 -0600
commitb2b8520880e9d458adbd279a34b831f8d6b68d40 (patch)
tree8e29536c38518715bbeee0fbbebc6ef0c85889ea /py/objnamedtuple.c
parentc06fc8e02dc7c17e827e3fe736dc7226d7819452 (diff)
Always use preprocessor for MICROPY_ERROR_REPORTING
This ensures that only the translate("") alternative that will be used is seen after preprocessing. Improves the quality of the Huffman encoding and reduces binary size slightly. Also makes one "enhanced" error message only occur when ERROR_REPORTING_DETAILED: Instead of the word-for-word python3 error message "Type object has no attribute '%q'", the message will be "'type' object has no attribute '%q'". Also reduces binary size. (that's rolled into this commit as it was right next to a change to use the preprocessor for MICROPY_ERROR_REPORTING) Note that the odd semicolon after "value_error:" in parsenum.c is necessary due to a detail of the C grammar, in which a declaration cannot follow a label directly.
Diffstat (limited to 'py/objnamedtuple.c')
-rw-r--r--py/objnamedtuple.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c
index ab2f2f3c0..8b595da57 100644
--- a/py/objnamedtuple.c
+++ b/py/objnamedtuple.c
@@ -102,17 +102,17 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const
n_kw = kw_args->used;
}
if (n_args + n_kw != num_fields) {
- if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
+ #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
- } else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL) {
+ #elif MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NORMAL
mp_raise_TypeError_varg(
translate("function takes %d positional arguments but %d were given"),
num_fields, n_args + n_kw);
- } else if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED) {
+ #else
mp_raise_TypeError_varg(
translate("%q() takes %d positional arguments but %d were given"),
type->base.name, num_fields, n_args + n_kw);
- }
+ #endif
}
// Create a tuple and set the type to this namedtuple
@@ -128,20 +128,20 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const
qstr kw = mp_obj_str_get_qstr(kw_args->table[i].key);
size_t id = mp_obj_namedtuple_find_field(type, kw);
if (id == (size_t)-1) {
- if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
+ #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
- } else {
+ #else
mp_raise_TypeError_varg(
translate("unexpected keyword argument '%q'"), kw);
- }
+ #endif
}
if (tuple->items[id] != MP_OBJ_NULL) {
- if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
+ #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_arg_error_terse_mismatch();
- } else {
+ #else
mp_raise_TypeError_varg(
translate("function got multiple values for argument '%q'"), kw);
- }
+ #endif
}
tuple->items[id] = kw_args->table[i].value;
}