refactor: simplify Event.parse_dates method
- Dominant language
- Python
- Stars
- 451
- Forks
- 707
- Avg merge
- 22h 59m
- Merged PRs (30d)
- 91
Description
## Description
The `parse_dates` static method on the `Event` model has grown complex over time. It currently carries a `# noqa: PLR0911` suppression (too many return statements) and a TODO comment requesting refactoring.
**File:** `backend/apps/owasp/models/event.py`, line 109
```python
# TODO(arkid15r): refactor this when there is a chance.
@staticmethod
def parse_dates(dates: str, start_date: date) -> date | None: # noqa: PLR0911
```
The method handles multiple date format cases via chained conditionals, regex patterns, and nested exception handling, making it hard to extend or test in isolation.
## What needs to change
- Extract sub-logic into clearly named private helper methods (e.g., `_parse_iso_date`, `_parse_range_date`)
- Remove the `# noqa: PLR0911` suppression by reducing return paths
- Keep the external behavior identical — only internal structure changes
- Ensure all existing edge case tests still pass
## Acceptance Criteria
- [ ] `parse_dates` delegates to clearly named helper methods
- [ ] `# noqa: PLR0911` suppression is removed
- [ ] All existing tests pass without modification
- [ ] New unit tests cover any previously untested branches
Contributor guide
Assessment
This issue has not been assessed yet.