Repository navigation
Fix ordinal suffix generation for large numbers ending in 11, 12, 13 - #556
Merged
Merged
Conversation
The `find_ordinal` utility incorrectly assigned "st", "nd", and "rd" suffixes to numbers greater than 20 that end in 11, 12, or 13 (e.g., 111 became "111st"). This commit modifies the logic to check `pos_num % 100` for the 11–13 range before falling back to the modulo 10 recursion. This ensures consistent "th" suffixes for these edge cases (e.g., "111th", "112th"). New regression tests have been added to `tests/test_utils.py` to cover these scenarios.
jd
approved these changes
Feb 17, 2026
Contributor
Merge Queue StatusRule:
This pull request spent 25 seconds in the queue, including 4 seconds running CI. Required conditions to merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a logical error in the
_utils.find_ordinalhelper where numbers greater than 20 ending in 11, 12, or 13 were incorrectly suffixed.The Issue:
Previously, the code checked for the 11–13 exception range only on the raw number. For numbers > 20, it recursed using
num % 10.111111 > 20-> recursefind_ordinal(1)-> returns"st"-> Output:"111st"(Incorrect)The Fix:
Added a check for
pos_num % 100to catch the 11–13 pattern for larger numbers before recursing.111 % 100is11-> returns"th"-> Output:"111th"(Correct)Changes:
tenacity/_utils.py: Added modulo 100 check.tests/test_utils.py: Added specific test cases for 111, 112, and 113.