fix(number, lists): correct negative ordinal suffixes and support general iterables with oxford_comma - #376
Open
miskatul-anwar wants to merge 6 commits into
Conversation
for more information, see https://pre-commit.ci
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.
Summary
This PR resolves two key issues and enhances developer ergonomics:
Negative Integer Ordinal Suffix Calculation (
src/humanize/number.py):ordinal()for negative integers (e.g.-21previously returned'-21th'due to Python's modulo behavior on negative numbers). Usingabs(value)ensures correct suffixes (e.g.,-1st,-2nd,-3rd,-11th,-21st).Iterable & Oxford Comma Support in
natural_list(src/humanize/lists.py):natural_listto accept any generalIterable(such as generators, tuples, sets) instead of strictly requiringlist.oxford_comma: bool = Falseparameter to format lists as'one, two, and three'.Source Import & Test Resilience (
src/humanize/__init__.py,tests/):try...except ImportErrorfallback for_version.pyin__init__.pyso importing directly from source without build artifacts works smoothly.pytest.importorskipfor optional test dependencies (freezegun,pytest-codspeed) to prevent test crashes in minimal development environments.Empirical Test Verification
Ran
pytest: