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

word_generator() changes #54

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

word_generator() changes #54

wants to merge 4 commits into from

Conversation

znarfm
Copy link
Contributor

@znarfm znarfm commented Nov 20, 2024

This pull request includes several improvements to the word_generator function in the bing_rewards/__init__.py file. The changes enhance error handling, ensure uniform random distribution, and improve code readability.

Enhancements to word_generator function:

  • Type hints: specified the return type as Generator[str, None, None].
  • Added yields and potential exceptions in the docstring.
  • Implemented error handling for FileNotFoundError and IOError, with appropriate error messages and re-raising of exceptions.
  • Ensured the function handles empty keyword files by raising a ValueError if the file size is zero. (Useful when implementing a feature to add your own .txt files for searches)
  • Improved the random starting position logic (to capture the whole txt file) and ensured clean line boundaries by discarding partial lines and skipping empty lines.

@jack-mil
Copy link
Owner

Ah, thanks for the contribution. Reading from the file always felt like a bit of a hack to me, and I didn't love my implementation.
I will take a look and try this when I have a chance.

If any of the Ruff linting errors seem unreasonable or unnecessary, I am open to disable or ignoring those errors. I kind of went overly zealous when setting up Ruff and configuring errors. Selecting almost everything is probably unnecessary, I was mostly interested in what Ruff would detect.

@znarfm
Copy link
Contributor Author

znarfm commented Nov 21, 2024

Mostly was just errors about using double quotes. Sorry, ruff linting is kinda new for me.

@jack-mil
Copy link
Owner

you should be able to set up your editor to auto format with Ruff using the project.toml config. Or use the ruff executable directly. Or even use the pre-commit hook. it's up to you

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