servo icon indicating copy to clipboard operation
servo copied to clipboard

Make string formatting more consistent in `CodegenRust.py`

Open saito828koki opened this issue 1 year ago • 3 comments

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.substitute with 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. fill function, instantiateJSToNativeConversionTemplate function)

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-tidy doesn'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 -d does not report any errors
  • [x] ./mach test-tidy does 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

saito828koki avatar Aug 16 '24 23:08 saito828koki

🔨 Triggering try run (#10434044962) for Linux WPT

github-actions[bot] avatar Aug 17 '24 17:08 github-actions[bot]

Test results for linux-wpt-layout-2020 from try job (#10434044962):

Flaky unexpected result (15)
  • TIMEOUT [expected PASS] /css/compositing/mix-blend-mode/mix-blend-mode-video.html (#32763)
  • OK /css/css-fonts/variations/at-font-face-font-matching.html (#20684)
    • FAIL [expected PASS] subtest: Matching font-weight: '399' should prefer '350 399' over '340 360'
      assert_equals: Unexpected font on test element expected 487 but got 532
      

  • FAIL [expected PASS] /css/css-values/vh_not_refreshing_on_chrome.html (#23385, #15570)
  • TIMEOUT /fetch/metadata/generated/css-images.sub.tentative.html (#29047)
    • TIMEOUT [expected PASS] subtest: background-image sec-fetch-site - HTTPS downgrade (header not sent)
      Test timed out
      

  • TIMEOUT /fetch/metadata/generated/element-img-environment-change.sub.html (#30111)
    • PASS [expected FAIL] subtest: sec-fetch-site - Not sent to non-trustworthy same-origin destination, no attributes
  • OK /html/browsers/browsing-the-web/navigating-across-documents/initial-empty-document/iframe-src-aboutblank-navigate-immediately.html (#29048)
    • PASS [expected FAIL] subtest: Navigating to a different document with form submission
  • ERROR [expected TIMEOUT] /html/canvas/element/manual/imagebitmap/createImageBitmap-flipY.html (#32745)
  • ERROR [expected TIMEOUT] /html/canvas/element/manual/imagebitmap/createImageBitmap-invalid-args.html (#32745)
  • TIMEOUT [expected CRASH] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_escaping-2.html (#22667)
    • TIMEOUT [expected FAIL] subtest: Check that popups from a sandboxed iframe escape the sandbox if allow-popups-to-escape-sandbox is used
      Test timed out
      

  • TIMEOUT [expected CRASH] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-2.html (#22154)
    • NOTRUN [expected FAIL] subtest: Check that popups from a sandboxed iframe do not escape the sandbox
  • OK /html/webappapis/dynamic-markup-insertion/document-write/module-static-import-delayed.html (#26243)
    • FAIL [expected PASS] subtest: document.write in an imported module
      assert_true: onload must be called expected true got false
      

  • TIMEOUT [expected OK] /resource-timing/nested-context-navigations-iframe.html (#24311)
    • TIMEOUT [expected PASS] subtest: Test that crossorigin iframe navigations are not observable by the parent, even after history navigations by the parent
      Test timed out
      

    • NOTRUN [expected PASS] subtest: Test that cross-site iframe navigations are not observable by the parent, even after history navigations by the parent
    • NOTRUN [expected PASS] subtest: Test that iframe navigations are not observable by the parent
    • NOTRUN [expected PASS] subtest: Test that crossorigin iframe navigations are not observable by the parent
    • NOTRUN [expected PASS] subtest: Test that cross-site iframe navigations are not observable by the parent
    • NOTRUN [expected PASS] subtest: Test that iframe refreshes are not observable by the parent
    • NOTRUN [expected PASS] subtest: Test that crossorigin iframe refreshes are not observable by the parent
    • NOTRUN [expected PASS] subtest: Test that cross-site iframe refreshes are not observable by the parent
  • OK /resource-timing/status-codes-create-entry.html (#28675)
    • PASS [expected FAIL] subtest: Make sure all status codes are reported
  • TIMEOUT /resource-timing/test_resource_timing.https.html (#25216)
    • FAIL [expected PASS] subtest: PerformanceEntry has correct name, initiatorType, startTime, and duration (img)
      assert_equals: expected 17206272 but got 17206016
      

  • TIMEOUT [expected OK] /webmessaging/with-ports/018.html (#24485)
    • TIMEOUT [expected PASS] subtest: origin of the script that invoked the method, javascript:
      Test timed out
      

Stable unexpected results that are known to be intermittent (17)
  • FAIL [expected PASS] /_mozilla/css/iframe/hide_and_show.html (#15265)
  • FAIL [expected PASS] /css/css-sizing/dynamic-available-size-iframe.html (#31559)
  • OK /css/cssom-view/MediaQueryList-addListener-removeListener.html (#24569)
    • FAIL [expected PASS] subtest: listeners are called correct number of times
      assert_equals: expected 9 but got 8
      

    • FAIL [expected PASS] subtest: listeners are called in order they were added
      assert_array_equals: lengths differ, expected array ["1st", "2nd"] length 2, got [] length 0
      

  • OK [expected TIMEOUT] /css/cssom-view/MediaQueryList-extends-EventTarget.html (#25269)
    • PASS [expected TIMEOUT] subtest: addEventListener "once" option is respected
    • PASS [expected NOTRUN] subtest: removeEventListener removes listener
  • OK /css/cssom-view/matchMedia.html (#31428)
    • PASS [expected FAIL] subtest: iframe.matchMedia("(width: 200px)") matches
    • PASS [expected FAIL] subtest: iframe.matchMedia("(min-width: 150px)") matches
  • OK /html/browsers/browsing-the-web/navigating-across-documents/empty-iframe-load-event.html (#29066)
    • PASS [expected FAIL] subtest: Check execution order on load handler
    • PASS [expected FAIL] subtest: Check execution order from nested timeout
  • OK /html/browsers/history/the-history-interface/traverse_the_history_3.html (#21383)
    • FAIL [expected PASS] subtest: 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])
      

  • OK [expected TIMEOUT] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_escaping-3.html (#24057)
    • FAIL [expected TIMEOUT] subtest: 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"
      

  • TIMEOUT [expected CRASH] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-1.html (#24066)
    • NOTRUN [expected FAIL] subtest: Check that popups from a sandboxed iframe do not escape the sandbox
  • OK [expected TIMEOUT] /html/semantics/embedded-content/the-iframe-element/iframe_sandbox_popups_nonescaping-3.html (#24066)
    • FAIL [expected NOTRUN] subtest: 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"
      

  • TIMEOUT [expected OK] /html/semantics/embedded-content/the-iframe-element/sandbox-top-navigation-cross-site.tentative.sub.window.html (#31754)
    • TIMEOUT [expected FAIL] subtest: A cross-site unsandboxed iframe navigation consumes user activation and disallows top-level navigation.
      Test timed out
      

  • TIMEOUT [expected OK] /html/semantics/embedded-content/the-iframe-element/sandbox-top-navigation-same-site.tentative.sub.window.html (#32117)
    • TIMEOUT [expected FAIL] subtest: A same-site unsandboxed iframe navigation does not consume user activation and allows top-level navigation.
      Test timed out
      

  • TIMEOUT [expected OK] /html/semantics/embedded-content/the-iframe-element/sandbox-top-navigation-user-activation-sticky.tentative.sub.window.html (#32154)
    • TIMEOUT [expected FAIL] subtest: Allow top with user activation + user activation
      Test timed out
      

  • OK /html/webappapis/update-rendering/child-document-raf-order.html (#33028)
    • PASS [expected FAIL] subtest: Ordering of steps in "Update the Rendering" - child document requestAnimationFrame order
  • ERROR /resource-timing/content-type-parsing.html (#29131)
    • TIMEOUT [expected FAIL] subtest: mime-type 16 : text/html;charset=gbk
      Test timed out
      

    • NOTRUN [expected TIMEOUT] subtest: mime-type 17 : text/html;charset=gbk
  • OK [expected CRASH] /url/failure.html (#28574)
  • OK [expected TIMEOUT] /webstorage/localstorage-about-blank-3P-iframe-opens-3P-window.partitioned.html (#29053)
    • PASS [expected TIMEOUT] subtest: StorageKey: test 3P about:blank window opened from a 3P iframe

github-actions[bot] avatar Aug 17 '24 18:08 github-actions[bot]

✨ Try run (#10434044962) succeeded.

github-actions[bot] avatar Aug 17 '24 18:08 github-actions[bot]

Rebased onto the latest main to resolve conflicts.

saito828koki avatar Aug 18 '24 03:08 saito828koki