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

Missing exception handling for invalid keyword arguments #67

Open
ChristianGeng opened this issue Dec 19, 2024 · 0 comments
Open

Missing exception handling for invalid keyword arguments #67

ChristianGeng opened this issue Dec 19, 2024 · 0 comments

Comments

@ChristianGeng
Copy link
Member

Description: The word_error_rate function does not handle cases where an invalid keyword argument is passed. For example, if the user accidentally types norm="truthx" instead of norm="truth", the function will not raise an error. Instead, it will simply ignore the invalid keyword argument and use the default value.

Expected behavior: The function should raise a ValueError or TypeError when an invalid keyword argument is passed.

Example Test:

with pytest.raises(ValueError):
    word_error_rate(truth=[["lorem", "ipsum"]], prediction=[["lorm", "ipsum"]], norm="truthx")

Fix: Add exception handling to the word_error_rate function to raise an error when an invalid keyword argument is passed.

Stub how this could be changed.

  def word_error_rate(truth, prediction, **kwargs):
      if "norm" in kwargs and kwargs["norm"] not in ["truth", "longest"]:
          raise ValueError(f"Invalid value for 'norm': {kwargs['norm']}")
      # ... rest of the function ...

This fix will ensure that the function raises an error when
an invalid keyword argument is passed, making it easier for users to catch and fix typos.

/cc @hagenw

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