Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine.plural raises unexpected IndexError #172

Open
Harmon758 opened this issue Jan 7, 2023 · 4 comments
Open

engine.plural raises unexpected IndexError #172

Harmon758 opened this issue Jan 7, 2023 · 4 comments

Comments

@Harmon758
Copy link

This might be considered invalid input, but engine.plural accepts multiple words.
When doing so, it can raise an unexpected IndexError:

>>> import inflect
>>> engine = inflect.engine()
>>> engine.plural("I'm only here for a minute, John.")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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.

@VeenaPulicharla
Copy link

VeenaPulicharla commented Jan 18, 2023

Facing same issue, it's working is strange
Screenshot 2023-01-18 at 4 46 54 PM

@jaraco
Copy link
Owner

jaraco commented Jan 19, 2023

That seems like invalid input to me. What would you expect when pluralizing a phrase?

@VeenaPulicharla
Copy link

VeenaPulicharla commented Jan 19, 2023

@jaraco, I wouldn't expect it to break and could you please explain why it's is not raising the error in the first run and raising in the second run, there is no much difference in the input except spaces

@jaraco
Copy link
Owner

jaraco commented Jan 20, 2023

could you please explain why it's is not raising the error in the first run and raising in the second run, there is no much difference in the input except spaces

I'm not familiar enough with the implementation to know what's expected here. I would need to trace the inputs through the code and try to infer what the code is trying to do. Harmon has determined that sometimes the length of the words being processed is a mismatch before and after postprocess. There may be a bug there, but I'm not confident that this use case should be supported at all.

I wouldn't expect it to break

I think I would expect it to break, if it can't provide a reasonable response. Perhaps there should be a check and if the input is something unexpected (like pipes or long phrases), it should just raise a ValueError early.

Regardless, this project is community-supported, so I'll leave this one for someone to investigate and propose a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants