aboutsummaryrefslogtreecommitdiff
path: root/ports/unix/mpconfigport.h
diff options
context:
space:
mode:
authorNicko van Someren2019-11-16 17:07:11 -0700
committerDamien George2019-12-28 23:55:15 +1100
commit4c93955b7b4d3d860aed1551ca6231ac4e388e69 (patch)
tree33d4e13a6076d847f98da761febeb5f745e94a3c /ports/unix/mpconfigport.h
parent007a704d82f07d1482dae6f265fecf5710266767 (diff)
py/objslice: Add support for indices() method on slice objects.
Instances of the slice class are passed to __getitem__() on objects when the user indexes them with a slice. In practice the majority of the time (other than passing it on untouched) is to work out what the slice means in the context of an array dimension of a particular length. Since Python 2.3 there has been a method on the slice class, indices(), that takes a dimension length and returns the real start, stop and step, accounting for missing or negative values in the slice spec. This commit implements such a indices() method on the slice class. It is configurable at compile-time via MICROPY_PY_BUILTINS_SLICE_INDICES, disabled by default, enabled on unix, stm32 and esp32 ports. This commit also adds new tests for slice indices and for slicing unicode strings.
Diffstat (limited to 'ports/unix/mpconfigport.h')
-rw-r--r--ports/unix/mpconfigport.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h
index 40cd1f570..d633726a1 100644
--- a/ports/unix/mpconfigport.h
+++ b/ports/unix/mpconfigport.h
@@ -90,6 +90,7 @@
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1)
#define MICROPY_PY_ARRAY_SLICE_ASSIGN (1)
#define MICROPY_PY_BUILTINS_SLICE_ATTRS (1)
+#define MICROPY_PY_BUILTINS_SLICE_INDICES (1)
#define MICROPY_PY_SYS_EXIT (1)
#define MICROPY_PY_SYS_ATEXIT (1)
#if MICROPY_PY_SYS_SETTRACE