diff options
author | Damien George <damien@micropython.org> | 2022-04-15 00:45:25 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-05-18 16:18:35 +1000 |
commit | 079f3e5e5bc03f8e7af34a5e6e8db8bf2c570ba7 (patch) | |
tree | 75016a255691e9268b31ee58243f2ad5ff4a65e0 /docs/reference | |
parent | 761d2f67415ba43f64c7b04b6ea72fd4b65afc50 (diff) | |
download | micropython-079f3e5e5bc03f8e7af34a5e6e8db8bf2c570ba7.tar.gz micropython-079f3e5e5bc03f8e7af34a5e6e8db8bf2c570ba7.zip |
py/parse: Allow all constant objects to be used in "X = const(o)".
Now that constant tuples are supported in the parser, eg (1, True, "str"),
it's a small step to allow anything that is a constant to be used with the
pattern:
from micropython import const
X = const(obj)
This commit makes the required changes to allow the following types of
constants:
from micropython import const
_INT = const(123)
_FLOAT = const(1.2)
_COMPLEX = const(3.4j)
_STR = const("str")
_BYTES = const(b"bytes")
_TUPLE = const((_INT, _STR, _BYTES))
_TUPLE2 = const((None, False, True, ..., (), _TUPLE))
Prior to this, only integers could be used in const(...).
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'docs/reference')
-rw-r--r-- | docs/reference/constrained.rst | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/docs/reference/constrained.rst b/docs/reference/constrained.rst index 8d3ba0e3af..8b64fd98fc 100644 --- a/docs/reference/constrained.rst +++ b/docs/reference/constrained.rst @@ -112,7 +112,8 @@ with an underscore as in ``_COLS``: this symbol is not visible outside the module so will not occupy RAM. The argument to ``const()`` may be anything which, at compile time, evaluates -to an integer e.g. ``0x100`` or ``1 << 8``. It can even include other const +to a constant e.g. ``0x100``, ``1 << 8`` or ``(True, "string", b"bytes")`` +(see section below for details). It can even include other const symbols that have already been defined, e.g. ``1 << BIT``. **Constant data structures** |