Skip to content

Handle signed numeric literals in inflect interpolation - #281

Merged
jaraco merged 1 commit into
jaraco:mainfrom
AryanRG:fix/signed-numeric-interpolation
Oct 20, 2026
Merged

jaraco merged 1 commit into
jaraco:mainfrom
AryanRG:fix/signed-numeric-interpolation

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

engine().inflect("number_to_words(-12)") raises AttributeError before calling number_to_words, although the direct call returns minus twelve. Python parses numeric signs as ast.UnaryOp, which the interpolation argument decoder does not handle. Explicit + signs fail the same way.

Decode unary plus/minus literals with ast.literal_eval. Add 12 regression cases covering positional/keyword arguments, floats, counts, and list/tuple elements, five rejection controls, and a Towncrier fragment.

Validation on CPython 3.13.12 (macOS):

  • With the exact base decoder: 12 new cases fail; five rejection controls pass. With the patch, full tests/doctests: 231 passed, 16 xfailed.
  • Standard tox is not green: 7 failed, 261 passed, 16 xfailed; all seven failures are Ruff checks. A pristine base checkout using the same tox Python/plugins has the same seven failures (244 passed, 16 xfailed). Ruff 0.17.1 diagnostics are identical per file: 169 on each side; pinned Ruff 0.12.0 likewise has 56 on each side. Both changed Python files pass formatting.
  • Other Python versions, the docs build, and hosted CI have not been verified locally.

Adjacent #279 restores persistent count after interpolation exceptions. This change handles valid signed arguments before dispatch and leaves that exception-restoration fix separate.

AI assistance was used to prepare the implementation and regression tests.

@jaraco
jaraco merged commit dc1344e into jaraco:main Oct 20, 2026
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