jaraco / jaraco/inflect

`engine.plural` raises unexpected `IndexError`

Open
#172 4 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
Python
Stars
1.1k
Forks
127
PR merge metrics
No merged PRs in 30d

Description

This might be considered invalid input, but `engine.plural` accepts multiple words.
When doing so, it can raise an unexpected `IndexError`:
```pycon
>>> import inflect
>>> engine = inflect.engine()
>>> engine.plural("I'm only here for a minute, John.")
Traceback (most recent call last):
File "", line 1, in
File "pydantic\decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
File "pydantic\decorator.py", line 134, in pydantic.decorator.ValidatedFunction.call
File "pydantic\decorator.py", line 206, in pydantic.decorator.ValidatedFunction.execute
File "C:\Program Files\Python39\lib\site-packages\inflect\__init__.py", line 2403, in plural
plural = self.postprocess(
File "C:\Program Files\Python39\lib\site-packages\inflect\__init__.py", line 2375, in postprocess
result[index] = result[index].capitalize()
IndexError: list index out of range
```

This seems to be because `engine.postprocess` expects the `inflected` it's passed to be the same number of words as the `orig` it's passed, but that's not necessarily the case.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in inflect/__init__.py at engine.plural and postprocess, using the multiword example in the issue to reproduce the IndexError. Trace how the inflected and original word lists differ, then add coverage for this input and verify that plural() no longer raises an unexpected IndexError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.