fix(cleaners): prevent UnboundLocalError in _get_indexed_match when pattern is absent - #4441
Open
mayuriphad wants to merge 1 commit into
Open
Conversation
…attern is absent Closes Unstructured-IO#4427
Contributor
There was a problem hiding this comment.
No issues found across 2 files
Shadow auto-approve: would auto-approve. Focused bug fix preventing UnboundLocalError by initializing loop counter and raising a clear ValueError when no matches exist; regression tests pin the corrected behavior for both the helper and public functions.
Re-trigger cubic
Author
|
Hi maintainers — just checking in on this PR since it hasn't had a maintainer review yet. Happy to make any changes needed; let me know if anything's unclear or if I should split/rework it. Thanks for your time! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #4427
extract_text_before()andextract_text_after()raised anUnboundLocalErrorinstead of aValueErrorwhen the target pattern was not present in the input text. The helper_get_indexed_match()referenced loop counteriin its formatted error message, which remained unassigned whenre.finditerproduced 0 matches.Solution
i = -1before the match iteration loop.Result with index {index} was not found. No matches were found.when no matches are detected.test_unstructured/cleaners/test_extract.py.