Skip to content

Commit 1bc5342

Browse files
committed
objtype: Add special unary methods __pos__, __neg__, __invert__.
Conditional on MICROPY_PY_ALL_SPECIAL_METHODS.
1 parent fdaac1d commit 1bc5342

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

py/objtype.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,11 @@ mp_obj_t instance_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, c
330330
const qstr mp_unary_op_method_name[] = {
331331
[MP_UNARY_OP_BOOL] = MP_QSTR___bool__,
332332
[MP_UNARY_OP_LEN] = MP_QSTR___len__,
333-
//[MP_UNARY_OP_POSITIVE,
334-
//[MP_UNARY_OP_NEGATIVE,
335-
//[MP_UNARY_OP_INVERT,
333+
#if MICROPY_PY_ALL_SPECIAL_METHODS
334+
[MP_UNARY_OP_POSITIVE] = MP_QSTR___pos__,
335+
[MP_UNARY_OP_NEGATIVE] = MP_QSTR___neg__,
336+
[MP_UNARY_OP_INVERT] = MP_QSTR___invert__,
337+
#endif
336338
[MP_UNARY_OP_NOT] = MP_QSTR_, // don't need to implement this, used to make sure array has full size
337339
};
338340

py/qstrdefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ Q(__truediv__)
8585
Q(__floordiv__)
8686
Q(__iadd__)
8787
Q(__isub__)
88+
Q(__invert__)
89+
Q(__neg__)
90+
Q(__pos__)
8891
#endif
8992

9093
Q(micropython)

0 commit comments

Comments
 (0)