Skip to content

Conversation

@jepler
Copy link
Contributor

@jepler jepler commented Nov 30, 2025

Summary

I was not able to find an explicit test for "fstring nested replacement fields", like f"{x:{space}.{prec}}". So I added several cases to the existing test string_fstring.py.

Testing

I locally ran make test//fstring in the unix port.

Trade-offs and Alternatives

Are there more cases that should be tested?

Should the test be in its own file?

This does not actually cover any additional lines but unless I overlooked an existing test it does cover new functionality not previously covered.

@codecov
Copy link

codecov bot commented Nov 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.38%. Comparing base (83131c1) to head (c734ae9).
⚠️ Report is 37 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #18495   +/-   ##
=======================================
  Coverage   98.38%   98.38%           
=======================================
  Files         171      171           
  Lines       22301    22301           
=======================================
  Hits        21940    21940           
  Misses        361      361           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@stinos
Copy link
Contributor

stinos commented Dec 1, 2025

When I read 'nested' I thought this was about f"{f'{1}'}" (which Micropython does not support but with a cryptic 'TypeError: 'str' object isn't callable' error.)

Nitpick: perhaps this should be named 'f-string with nested brackets' ?

@jepler jepler changed the title string_fstring: Add test for nested fstrings. tests: Test nested curly braces in fstrings. Dec 1, 2025
@jepler
Copy link
Contributor Author

jepler commented Dec 1, 2025

When I read 'nested' I thought this was about f"{f'{1}'}" (which Micropython does not support but with a cryptic 'TypeError: 'str' object isn't callable' error.)

Nitpick: perhaps this should be named 'f-string with nested brackets' ?

Good idea. I re-titled and re-worded, but I used the term "curly braces" same as the cpython documentation.

@stinos
Copy link
Contributor

stinos commented Dec 2, 2025

used the term "curly braces" same as the cpython documentation

Thanks, makes sense. Can you change it in the comment on the test as well?

Signed-off-by: Jeff Epler <jepler@unpythonic.net>
@jepler
Copy link
Contributor Author

jepler commented Dec 2, 2025

I've revised yet again what this test fragment explains it is testing. The CPython docs end up explaining it like this:

Top-level format specifiers may include nested replacement fields. These nested fields may include their own conversion fields and format specifiers, but may not include more deeply nested replacement fields. The format specifier mini-language is the same as that used by the str.format() method.

This is different than the following cases of nested curly braces: f"{{ }}" (doubled curly braces, whether matched or not, indicate single literal curly braces in the output) and f{ {3}} (a set literal inside an f-string replacement field) and are already tested.

@jepler jepler changed the title tests: Test nested curly braces in fstrings. tests: Test fstring nested replacement fields. Dec 2, 2025
@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Dec 16, 2025
Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test.

I didn't realise that MicroPython supported this!

@dpgeorge
Copy link
Member

Rebased and merged in ef567dc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Relates to tests/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants