Skip to content

Fix short acronym boundaries in camel_to_underscore - #57

Merged
wolph merged 1 commit into
wolph:developfrom
pralav-25:fix-short-acronym-boundaries
Oct 11, 2026
Merged

wolph merged 1 commit into
wolph:developfrom
pralav-25:fix-short-acronym-boundaries

Conversation

@pralav-25

Copy link
Copy Markdown
Contributor

camel_to_underscore("IPad") currently returns "ipad", and "ABCd" returns "abcd". The acronym boundary check requires three preceding capitals and an offset greater than three, so it misses short acronyms and boundaries near the beginning of a name.

Check the two preceding letters instead. This returns "i_pad" and "ab_cd", keeps the final capital with the following word, and preserves existing underscore/digit behavior. Add regression cases for short prefixes, leading underscores, and a longer acronym.

Validation on Python 3.12:

  • The new regression cases fail before the fix.
  • Full pytest suite: 348 passed; 100% statement and branch coverage.
  • Ruff lint/format and mypy/Pyright for the changed files pass.

Prepared with AI assistance and verified locally.

@wolph
wolph merged commit 33b595e into wolph:develop Oct 11, 2026
17 checks passed
wolph added a commit that referenced this pull request Oct 11, 2026
#57 moved the acronym boundary check from three preceding capitals to
two, which split a plural acronym before its trailing s: IDs became
i_ds and UserIDs became user_i_ds, where 4.1.0 returned ids and
user_ids. A lone s that ends the word now stays with the acronym, which
also turns GetURLs into get_urls instead of get_ur_ls.
@wolph

wolph commented Oct 11, 2026

Copy link
Copy Markdown
Owner

That's a silly one indeed, the boundary check never looked at short acronyms. Thank you for the fix and the tests!

I've built on top of it in 1bb0458 so plural acronyms like IDs and URLs stay whole. I'm working on a new release, should be out soon :)

@wolph

wolph commented Oct 11, 2026

Copy link
Copy Markdown
Owner

I've created a new release (v4.1.1) which includes your fix, thanks again for the help :)

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