-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
py: Add PEP 750 template strings support #17557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
py: Add PEP 750 template strings support #17557
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #17557 +/- ##
==========================================
- Coverage 98.57% 98.53% -0.04%
==========================================
Files 169 172 +3
Lines 21968 22637 +669
==========================================
+ Hits 21654 22306 +652
- Misses 314 331 +17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code size report:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! This will be nice to have for the webassembly port.
I didn't do a review yet, but there will need to be tests to get full coverage of the new code.
@dpgeorge Thank you for the feedback and for taking time to look at this! I'm glad this will be useful for the webassembly port. I'll add more tests to ensure full coverage when I find time. |
@koxudaxi slightly off topic - but I notice you'll be at EuroPython in Prague, as will I. We should look out for each other and have a coffee or lunch together! 🇪🇺 🐍 |
@ntoll Sounds good! See you in Prague. ☕ |
330b05f
to
7a1dc11
Compare
Implements template strings (t-strings) as specified in PEP 750. Includes Template and Interpolation objects, expression parser, string.templatelib module, tests and documentation. Enabled for Unix, Windows, and WebAssembly ports. Signed-off-by: Koudai Aono <[email protected]>
7a1dc11
to
50dd4d1
Compare
I tried really hard to make 100% coverage but some code is never called and I cannot cover it. Do you know how to fix this? |
|
||
A flag for `keys()`, `values()`, `items()` methods to specify that | ||
A flag for :meth:`btree.keys`, :meth:`btree.values`, :meth:`btree.items` methods to specify that | ||
scanning should be inclusive of the end key. | ||
|
||
.. data:: DESC | ||
|
||
A flag for `keys()`, `values()`, `items()` methods to specify that | ||
A flag for :meth:`btree.keys`, :meth:`btree.values`, :meth:`btree.items` methods to specify that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I faced an error when building with Sphinx because it conflicted with string.templatelib.Template.values
. To solve this problem, I renamed the values attribute in btree to be more explicit.
@dpgeorge |
Summary
Implements PEP 750 template strings for MicroPython.
Started in discussion #17497. Template strings (t-strings) are new in Python 3.14 - they return Template objects instead of strings, so you can access the literal parts and expressions separately.
Changes:
Usage:
Testing
Tested on unix port with both MICROPY_PY_TSTRINGS enabled and disabled.
Test coverage:
All existing tests continue to pass. New tests added in
tests/basics/string_template*.py
.Ports tested: Unix (other ports need testing)
Trade-offs and Alternatives
Adds ~240 bytes when enabled on unix port. When disabled, no impact.
Worth it because:
Config: Enabled by default when MICROPY_CONFIG_ROM_LEVEL >= EXTRA_FEATURES.
Needs MICROPY_PY_FSTRINGS=1.
To disable:
make CFLAGS_EXTRA=-DMICROPY_PY_TSTRINGS=0