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

Let Input module kwarg accept strings #597

Merged
merged 2 commits into from
Dec 28, 2024

Conversation

bosd
Copy link
Collaborator

@bosd bosd commented Dec 23, 2024

Superseeding #266

jagilley and others added 2 commits December 23, 2024 10:52
Reduce complexity
Removed unnecessary list conversion: The templates = list(templates) line is removed as it's not needed since we're iterating through the templates directly.
Removed result initialization: The result variable initialization is removed as we're now returning directly from the loop if a match is found.
Return directly on match: If a template matches, the function now returns the result of template.extract directly within the loop.
Simplified OCR fallback: The OCR fallback logic is simplified by directly returning the result if a template is found.
Explanation:

The original code had some unnecessary steps and nested conditions that increased the complexity. By removing the redundant list conversion and returning directly from the loop when a match is found, we simplify the control flow and reduce the cognitive complexity of the function.

The simplified OCR fallback logic also contributes to reducing the complexity by avoiding unnecessary nesting and making the code easier to follow.

Added typehint for `Templates`. This fixes mypy error.

Changes in ocrmypdf fallback:
Renamed template to templates_matched: I renamed the template variable to templates_matched in the assignment to make it clearer that extract_data_fallback_ocrmypdf returns a list of templates.
Checked for matched templates: I added a check if templates_matched: to ensure that at least one template matched before trying to access the first element.
Assigned the first matched template: If templates_matched is not empty, I assign the first template in the list to the template variable.
@bosd bosd added type:enhancement New feature or request refactoring Refactoring labels Dec 23, 2024
@bosd bosd merged commit 4531ff5 into invoice-x:master Dec 28, 2024
12 of 13 checks passed
@bosd bosd deleted the input-module-strings branch December 28, 2024 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactoring type:enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants