You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: handle StopIteration exceptions and enhance documentation
This PR refactors generator functions to properly handle StopIteration, adds missing docstrings for modules and functions, audits file path controls, and merges nested with statements in tests.
- Unguarded next inside generator: Previously, multiple `next(data)` calls in generator functions were unguarded, which could raise unhandled `StopIteration` exceptions and crash the generator. Each `next` call is now wrapped in a `try/except StopIteration` block, with appropriate `return`, `continue`, or `pass` behavior to allow graceful termination or skipping of iterations.
- Missing module/function docstring: Several modules and internal functions lacked documentation, making it hard to understand their purpose and usage. We added comprehensive module-level and function-level docstrings across the JSON and XML parsing modules, describing the inputs, outputs, and generator behavior to improve code clarity and maintainability.
- Audit required: External control of file name or path: We reviewed the CSV loader to ensure it validates file existence and type, mitigating risks of path injection or unauthorized file access. Tests were supplemented and consolidated to confirm that invalid paths correctly raise `FileNotFoundError` or `ValueError` as expected.
- `with` statements can be merged: Tests contained nested `with` statements that could be simplified for better readability. We merged nested context managers into single `with` statements in the relevant test cases, reducing indentation and overall boilerplate.
> This Autofix was generated by AI. Please review the change before merging.
0 commit comments