diff options
| author | Jim Mussared <jim.mussared@gmail.com> | 2021-08-13 01:44:08 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2021-08-14 16:58:40 +1000 |
| commit | 692d36d779192f32371f7f9daa845b566f26968d (patch) | |
| tree | c3bfe2b4a90df72aad6b6eaac8bb6dac398516d9 /tests/run-tests.py | |
| parent | 162bf3c5d8055a9e9a17461878c9d058066283a5 (diff) | |
py: Implement partial PEP-498 (f-string) support.
This implements (most of) the PEP-498 spec for f-strings and is based on
https://github.com/micropython/micropython/pull/4998 by @klardotsh.
It is implemented in the lexer as a syntax translation to `str.format`:
f"{a}" --> "{}".format(a)
It also supports:
f"{a=}" --> "a={}".format(a)
This is done by extracting the arguments into a temporary vstr buffer,
then after the string has been tokenized, the lexer input queue is saved
and the contents of the temporary vstr buffer are injected into the lexer
instead.
There are four main limitations:
- raw f-strings (`fr` or `rf` prefixes) are not supported and will raise
`SyntaxError: raw f-strings are not supported`.
- literal concatenation of f-strings with adjacent strings will fail
"{}" f"{a}" --> "{}{}".format(a) (str.format will incorrectly use
the braces from the non-f-string)
f"{a}" f"{a}" --> "{}".format(a) "{}".format(a) (cannot concatenate)
- PEP-498 requires the full parser to understand the interpolated
argument, however because this entirely runs in the lexer it cannot
resolve nested braces in expressions like
f"{'}'}"
- The !r, !s, and !a conversions are not supported.
Includes tests and cpydiffs.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'tests/run-tests.py')
| -rwxr-xr-x | tests/run-tests.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/run-tests.py b/tests/run-tests.py index 619df5ed3..3e97a7c87 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -290,6 +290,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_const = False skip_revops = False skip_io_module = False + skip_fstring = False skip_endian = False has_complex = True has_coverage = False @@ -348,6 +349,11 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): if output != b"uio\n": skip_io_module = True + # Check if fstring feature is enabled, and skip such tests if it doesn't + output = run_feature_check(pyb, args, base_path, "fstring.py") + if output != b"a=1\n": + skip_fstring = True + # Check if emacs repl is supported, and skip such tests if it's not t = run_feature_check(pyb, args, base_path, "repl_emacs_check.py") if "True" not in str(t, "ascii"): @@ -543,6 +549,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): is_async = test_name.startswith(("async_", "uasyncio_")) is_const = test_name.startswith("const") is_io_module = test_name.startswith("io_") + is_fstring = test_name.startswith("string_fstring") skip_it = test_file in skip_tests skip_it |= skip_native and is_native @@ -555,6 +562,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_it |= skip_const and is_const skip_it |= skip_revops and "reverse_op" in test_name skip_it |= skip_io_module and is_io_module + skip_it |= skip_fstring and is_fstring if args.list_tests: if not skip_it: |
