Skip to content

fix: don't leave the engine in classical mode after a compare query - #268

Open
nikolauspschuetz wants to merge 1 commit into
jaraco:mainfrom
nikolauspschuetz:fix-plequal-classical-mode-leak
Open

nikolauspschuetz wants to merge 1 commit into
jaraco:mainfrom
nikolauspschuetz:fix-plequal-classical-mode-leak

Conversation

@nikolauspschuetz

Copy link
Copy Markdown

_plequal (the shared engine behind compare, compare_nouns, compare_verbs, compare_adjs) snapshots classical_dict to restore it, but the three early returns (eq/p:s/s:p) skip the restore, so a comparison leaves the engine in classical mode:

p = inflect.engine()
p.compare("formula", "formulae")   # 's:p'
p.plural("formula")                # 'formulae'  (was 'formulas')

A comparison query shouldn't mutate the engine — classical mode is controlled only by classical(). Wrapping the loop in try/finally restores the snapshot on every path. Added a regression test.

@nikolauspschuetz
nikolauspschuetz marked this pull request as ready for review August 23, 2026 14:23
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.

1 participant