Skip to content

Fix null_string_locale_max so it sorts after every PyICU key - #196

Merged
SethMMorton merged 1 commit into
SethMMorton:mainfrom
lenamonj:fix-icu-locale-max
Sep 10, 2026
Merged

SethMMorton merged 1 commit into
SethMMorton:mainfrom
lenamonj:fix-icu-locale-max

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 1, 2026

Copy link
Copy Markdown

null_string_locale_max in natsort/compat/locale.py (the PyICU branch) is b"x7f" * 50, which is the three ASCII bytes x, 7, f repeated, not the byte 0x7f. It is the sentinel prepended under ns.NUMAFTER | ns.LOCALE so numbers sort after strings, but any sort key whose first byte is above x (0x78) already sorts after it, so b"x7f"*50 > b"y" is False.

Change: b"\xff" * 50, the actual maximum byte, one line. Added tests/test_compat_locale.py, which loads the module with a stub icu in sys.modules and checks the sentinel against b"\xff" * 49 and b"\xfe" * 100. It fails on the current constant and passes with the change.

Verified on a fresh clone at e90771d: pytest 355 passed, ruff format --check, ruff check (no new findings beyond the CPY001 every file already reports on ruff 0.16.5), mypy --strict natsort tests unchanged from main. I could not install PyICU on this host (no ICU headers), so the PyICU code path itself was exercised only through the stub; CI installs libicu-dev and should cover it.

Found while running an AI-assisted code review on this repository; the change and the test are mine and were verified as described.

b"x7f" is three ASCII bytes, not the byte 0x7f, and any byte string
starting above 0x78 sorted after it. Use b"\xff" so the NUMAFTER
sentinel really is the maximum.
@codecov

codecov Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.80%. Comparing base (70745f5) to head (607eeee).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #196   +/-   ##
=======================================
  Coverage   97.80%   97.80%           
=======================================
  Files          10       10           
  Lines         637      637           
=======================================
  Hits          623      623           
  Misses         14       14           

☔ View full report in Codecov by Harness.
📢 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.

@SethMMorton
SethMMorton merged commit e2328c2 into SethMMorton:main Sep 10, 2026
15 of 17 checks passed
@lenamonj
lenamonj deleted the fix-icu-locale-max branch September 10, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants