Skip to content

Commit 98c4bc3

Browse files
committed
py: Add MICROPY_PY_ALL_SPECIAL_METHODS and __iadd__ special method under it.
1 parent 32bade1 commit 98c4bc3

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

py/mpconfig.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ typedef double mp_float_t;
376376
#define MICROPY_PY_BUILTINS_PROPERTY (1)
377377
#endif
378378

379+
// Whether to support complete set of special methods
380+
// for user classes, otherwise only the most used
381+
#ifndef MICROPY_PY_ALL_SPECIAL_METHODS
382+
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
383+
#endif
384+
379385
// Whether to support compile function
380386
#ifndef MICROPY_PY_BUILTINS_COMPILE
381387
#define MICROPY_PY_BUILTINS_COMPILE (0)

py/objtype.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,11 @@ const qstr mp_binary_op_method_name[] = {
378378
MP_BINARY_OP_INPLACE_XOR,
379379
MP_BINARY_OP_INPLACE_AND,
380380
MP_BINARY_OP_INPLACE_LSHIFT,
381-
MP_BINARY_OP_INPLACE_RSHIFT,
382-
MP_BINARY_OP_INPLACE_ADD,
383-
MP_BINARY_OP_INPLACE_SUBTRACT,
381+
MP_BINARY_OP_INPLACE_RSHIFT,*/
382+
#if MICROPY_PY_ALL_SPECIAL_METHODS
383+
[MP_BINARY_OP_INPLACE_ADD] = MP_QSTR___iadd__,
384+
#endif
385+
/*MP_BINARY_OP_INPLACE_SUBTRACT,
384386
MP_BINARY_OP_INPLACE_MULTIPLY,
385387
MP_BINARY_OP_INPLACE_FLOOR_DIVIDE,
386388
MP_BINARY_OP_INPLACE_TRUE_DIVIDE,

py/qstrdefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Q(__eq__)
7575
Q(__le__)
7676
Q(__ge__)
7777
Q(__reversed__)
78+
#if MICROPY_PY_ALL_SPECIAL_METHODS
79+
Q(__iadd__)
80+
#endif
7881

7982
Q(micropython)
8083
Q(bytecode)

unix/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#define MICROPY_PY_BUILTINS_FROZENSET (1)
6060
#define MICROPY_PY_BUILTINS_COMPILE (1)
6161
#define MICROPY_PY_MICROPYTHON_MEM_INFO (1)
62+
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
6263
#define MICROPY_PY_SYS_EXIT (1)
6364
#define MICROPY_PY_SYS_PLATFORM "linux"
6465
#define MICROPY_PY_SYS_MAXSIZE (1)

0 commit comments

Comments
 (0)