Skip to content

fix(number, lists): correct negative ordinal suffixes and support general iterables with oxford_comma - #376

Open
miskatul-anwar wants to merge 6 commits into
python-humanize:mainfrom
miskatul-anwar:fix/ordinal-negative-and-iterable-lists
Open

fix(number, lists): correct negative ordinal suffixes and support general iterables with oxford_comma#376
miskatul-anwar wants to merge 6 commits into
python-humanize:mainfrom
miskatul-anwar:fix/ordinal-negative-and-iterable-lists

Conversation

@miskatul-anwar

Copy link
Copy Markdown

Summary

This PR resolves two key issues and enhances developer ergonomics:

  1. Negative Integer Ordinal Suffix Calculation (src/humanize/number.py):

    • Fixed remainder calculations in ordinal() for negative integers (e.g. -21 previously returned '-21th' due to Python's modulo behavior on negative numbers). Using abs(value) ensures correct suffixes (e.g., -1st, -2nd, -3rd, -11th, -21st).
  2. Iterable & Oxford Comma Support in natural_list (src/humanize/lists.py):

    • Updated natural_list to accept any general Iterable (such as generators, tuples, sets) instead of strictly requiring list.
    • Added an optional oxford_comma: bool = False parameter to format lists as 'one, two, and three'.
  3. Source Import & Test Resilience (src/humanize/__init__.py, tests/):

    • Added a try...except ImportError fallback for _version.py in __init__.py so importing directly from source without build artifacts works smoothly.
    • Added pytest.importorskip for optional test dependencies (freezegun, pytest-codspeed) to prevent test crashes in minimal development environments.

Empirical Test Verification

Ran pytest:

319 passed, 3 skipped in 0.39s

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