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

Exception when processing special character strings #185

Open
szelenka opened this issue May 18, 2023 · 0 comments
Open

Exception when processing special character strings #185

szelenka opened this issue May 18, 2023 · 0 comments

Comments

@szelenka
Copy link

When a string is passed to plural which contains only a 's it will raise an IndexError Exception:

import inflect

p = inflect.engine()
p.plural("'s")

In version 5.6.0:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/_src/sqbu/voicea/wordcloud/.venv/lib/python3.11/site-packages/inflect/__init__.py", line 2376, in plural
    self._pl_special_adjective(word, count)
  File "/opt/_src/sqbu/voicea/wordcloud/.venv/lib/python3.11/site-packages/inflect/__init__.py", line 3102, in _pl_special_adjective
    trailing_s = "" if pl[-1] == "s" else "s"
                       ~~^^^^
IndexError: string index out of range

In version 6.0.4, it changes to a pydantic validation error:

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 "/opt/_src/sqbu/voicea/wordcloud/.venv/lib/python3.11/site-packages/inflect/__init__.py", line 2404, in plural
    self._pl_special_adjective(word, count)
  File "/opt/_src/sqbu/voicea/wordcloud/.venv/lib/python3.11/site-packages/inflect/__init__.py", line 3155, in _pl_special_adjective
    pl = self.plural_noun(mo.group(1))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pydantic/decorator.py", line 40, in pydantic.decorator.validate_arguments.validate.wrapper_function
  File "pydantic/decorator.py", line 133, in pydantic.decorator.ValidatedFunction.call
  File "pydantic/decorator.py", line 130, in pydantic.decorator.ValidatedFunction.init_model_instance
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for PluralNoun
text
  ensure this value has at least 1 characters (type=value_error.any_str.min_length; limit_value=1)

https://github.com/jaraco/inflect/blob/main/inflect/__init__.py#L3153-L3157

I would expect the method to return an empty string, or otherwise catch this type of error; since technically the input is a two character string (i.e. 's) but the validation strips out some of that to assert.

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

No branches or pull requests

1 participant