Enable RET502: Forbid empty return when function returns Optional
Open
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 17h 7m
- Merged PRs (30d)
- 358
Description
## Rule
**RET502**: `implicit-return-value`
## Purpose
Forbid implicit `return` (empty return) in functions that return Optional values. Forces explicit `return None` for clarity.
## Example
```python
# Bad
def get_user(id: int) -> Optional[User]:
if not valid:
return # RET502 - implicit None
return find_user(id)
# Good
def get_user(id: int) -> Optional[User]:
if not valid:
return None # explicit
return find_user(id)
```
## Auto-fix
✅ Available
## Notes
- Improves code readability by making None returns explicit
- Helps distinguish between "forgot to return" and "intentionally returning None"
JIRA Issue: BA-4022
Contributor guide
Assessment
This issue has not been assessed yet.