Skip to content

Restore persistent count when inflect interpolation fails - #279

Merged
jaraco merged 1 commit into
jaraco:mainfrom
00200200:codex/fix-inflect-count-restoration
Oct 20, 2026
Merged

jaraco merged 1 commit into
jaraco:mainfrom
00200200:codex/fix-inflect-count-restoration

Conversation

@00200200

@00200200 00200200 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Problem

engine.inflect() saves and restores the persistent count for interpolation, but restoration currently only happens on success. For example, after p.num(2), p.inflect("num(1) plural(missing_word)") raises NameError and leaves the count at 1, so a later p.plural("cat") unexpectedly returns the singular form.

Change

Restore the saved count in a finally block, while preserving the original exception. Add regression cases for invalid counts, undefined names and malformed expressions, plus successful interpolation, with original counts of None, 1 and 2. Include a bugfix release note.

Validation

  • On unchanged main: six new regression cases failed.
  • With the fix: all 12 new cases passed.
  • Full tests and doctests: 226 passed, 16 xfailed, 99% coverage.
  • Formatting passes; no new lint findings.

Prepared with OpenAI Codex assistance. The implementation and test results were reviewed locally.

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