Skip to content

py/objstr: Return 0 from str.count when end precedes start.#19005

Open
cuiweixie wants to merge 1 commit intomicropython:masterfrom
cuiweixie:fix/str-count-start-after-end
Open

py/objstr: Return 0 from str.count when end precedes start.#19005
cuiweixie wants to merge 1 commit intomicropython:masterfrom
cuiweixie:fix/str-count-start-after-end

Conversation

@cuiweixie
Copy link
Copy Markdown

Summary

  • str_count: if the slice resolves so that end < start, return 0 (same as CPython).
  • Fixes the empty-needle case where utf8_charlen was called with an inverted byte span.
  • Adds matching str / bytes regression lines in tests/basics/string_count.py and bytes_count.py (expected output from CPython via run-tests.py).

Matches CPython when start > end after index resolution.  An empty
needle previously used utf8_charlen with a negative span, giving wrong
results.  Add str/bytes regression tests.

Signed-off-by: Weixie Cui <cuiweixie@gmail.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.46%. Comparing base (2dc2e30) to head (f96a483).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19005   +/-   ##
=======================================
  Coverage   98.46%   98.46%           
=======================================
  Files         176      176           
  Lines       22784    22785    +1     
=======================================
+ Hits        22435    22436    +1     
  Misses        349      349           

☔ 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.

@github-actions
Copy link
Copy Markdown

Code size report:

Reference:  esp32/boards/SEEED_XIAO_ESP32C6: Add new XIAO board definition. [2dc2e30]
Comparison: py/objstr: Return 0 from str.count when end precedes start. [merge of f96a483]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +8 +0.002% PYBV10
      esp32:    +8 +0.000% ESP32_GENERIC
     mimxrt:    +8 +0.002% TEENSY40
        rp2:    +8 +0.001% RPI_PICO_W
       samd:    +8 +0.003% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +6 +0.001% VIRT_RV32

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

py-core Relates to py/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants