Make string formatting more consistent in `CodegenRust.py`
This PR is to integrate various string formatting styles in CodegenRust.py into f-string.
The key changes in this PR are
- Replace string concatenations using
+operator with f-string - Replace
string.Template.substitutewith f-string - Replace %formatting with f-string
This PR does NOT include the following changes
- Remove template strings that are used more than once
- Refactor formatting-related util functions (e.g.
fillfunction,instantiateJSToNativeConversionTemplatefunction)
notes:
- I deleted an unused function
onFailureInvalidEnumValue - Inside f-string, we need to double curly braces
{{}}to escape them (see https://docs.python.org/3/reference/lexical_analysis.html#f-strings ) - We cannot use backslash
\inside curly braces. For example,f"{'\n'.join(arr)}"is invalid. (On my local Mac,./mach test-tidydoesn't report it. Linux build on CI fails. I feel it would be better to have a way to check tidiness as strictly as CI locally.) - IMO, using ternary operators inside f-string sometimes makes it hard to read, so I avoid that kind of usage
- [x]
./mach build -ddoes not report any errors - [x]
./mach test-tidydoes not report any errors - [x] These changes fix #31846 (GitHub issue number if applicable)
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because this is a code style fix
🔨 Triggering try run (#10434044962) for Linux WPT
Test results for linux-wpt-layout-2020 from try job (#10434044962):Flaky unexpected result (15)
/css/compositing/mix-blend-mode/mix-blend-mode-video.html (#32763)/css/css-fonts/variations/at-font-face-font-matching.html (#20684)Matching font-weight: '399' should prefer '350 399' over '340 360'
assert_equals: Unexpected font on test element expected 487 but got 532
/css/css-values/vh_not_refreshing_on_chrome.html (#23385, #15570)/fetch/metadata/generated/css-images.sub.tentative.html (#29047)background-image sec-fetch-site - HTTPS downgrade (header not sent)
Test timed out
/fetch/metadata/generated/element-img-environment-change.sub.html (#30111)sec-fetch-site - Not sent to non-trustworthy same-origin destination, no attributes/html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/iframe-src-aboutblank-navigate-immediately.html (#29048)Navigating to a different document with form submission/html/canvas/element/manual/imagebitmap/createImageBitmap-flipY.html (#32745)/html/canvas/element/manual/imagebitmap/createImageBitmap-invalid-args.html (#32745)/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_escaping-2.html (#22667)Check that popups from a sandboxed iframe escape the sandbox if allow-popups-to-escape-sandbox is used
Test timed out
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-2.html (#22154)Check that popups from a sandboxed iframe do not escape the sandbox/html/webappapis/dynamic-markup-insertion/document-write/module-static-import-delayed.html (#26243)document.write in an imported module
assert_true: onload must be called expected true got false
/resource-timing/nested-context-navigations-iframe.html (#24311)Test that crossorigin iframe navigations are not observable by the parent, even after history navigations by the parent
Test timed out
Test that cross-site iframe navigations are not observable by the parent, even after history navigations by the parentTest that iframe navigations are not observable by the parentTest that crossorigin iframe navigations are not observable by the parentTest that cross-site iframe navigations are not observable by the parentTest that iframe refreshes are not observable by the parentTest that crossorigin iframe refreshes are not observable by the parentTest that cross-site iframe refreshes are not observable by the parent/resource-timing/status-codes-create-entry.html (#28675)Make sure all status codes are reported/resource-timing/test_resource_timing.https.html (#25216)PerformanceEntry has correct name, initiatorType, startTime, and duration (img)
assert_equals: expected 17206272 but got 17206016
/webmessaging/with-ports/018.html (#24485)origin of the script that invoked the method, javascript:
Test timed out
Stable unexpected results that are known to be intermittent (17)
/_mozilla/css/iframe/hide_and_show.html (#15265)/css/css-sizing/dynamic-available-size-iframe.html (#31559)/css/cssom-view/MediaQueryList-addListener-removeListener.html (#24569)listeners are called correct number of times
assert_equals: expected 9 but got 8
listeners are called in order they were added
assert_array_equals: lengths differ, expected array ["1st", "2nd"] length 2, got [] length 0
/css/cssom-view/MediaQueryList-extends-EventTarget.html (#25269)addEventListener "once" option is respectedremoveEventListener removes listener/css/cssom-view/matchMedia.html (#31428)iframe.matchMedia("(width: 200px)") matchesiframe.matchMedia("(min-width: 150px)") matches/html/browsers/browsing-the-web/navigating-across-documents/empty-iframe-load-event.html (#29066)Check execution order on load handlerCheck execution order from nested timeout/html/browsers/history/the-history-interface/traverse_the_history_3.html (#21383)Multiple history traversals, last would be aborted
assert_array_equals: Pages opened during history navigation expected property 1 to be 3 but got 2 (expected array [6, 3] got [6, 2])
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_escaping-3.html (#24057)Check that popups from a sandboxed iframe escape the sandbox if allow-popups-to-escape-sandbox is used
assert_equals: It came from a sandboxed iframe expected "null" but got "http://web-platform.test:8000"
/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-1.html (#24066)Check that popups from a sandboxed iframe do not escape the sandbox/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-3.html (#24066)Check that popups from a sandboxed iframe do not escape the sandbox
assert_equals: It came from a sandboxed iframe expected "null" but got "http://web-platform.test:8000"
/html/semantics/embedded-content/the-iframe-element/sandbox-top-navigation-cross-site.tentative.sub.window.html (#31754)A cross-site unsandboxed iframe navigation consumes user activation and disallows top-level navigation.
Test timed out
/html/semantics/embedded-content/the-iframe-element/sandbox-top-navigation-same-site.tentative.sub.window.html (#32117)A same-site unsandboxed iframe navigation does not consume user activation and allows top-level navigation.
Test timed out
/html/semantics/embedded-content/the-iframe-element/sandbox-top-navigation-user-activation-sticky.tentative.sub.window.html (#32154)Allow top with user activation + user activation
Test timed out
/html/webappapis/update-rendering/child-document-raf-order.html (#33028)Ordering of steps in "Update the Rendering" - child document requestAnimationFrame order/resource-timing/content-type-parsing.html (#29131)mime-type 16 : text/html;charset=gbk
Test timed out
mime-type 17 : text/html;charset=gbk/url/failure.html (#28574)/webstorage/localstorage-about-blank-3P-iframe-opens-3P-window.partitioned.html (#29053)StorageKey: test 3P about:blank window opened from a 3P iframe
✨ Try run (#10434044962) succeeded.
Rebased onto the latest main to resolve conflicts.