-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededpriority:lowrefactor
Description
Feature Description
Add Python type hints to utility functions to improve code readability and enable better IDE support and static type checking.
Problem Statement
Several utility functions in the project lack type hints, making it harder for new contributors to understand expected inputs and outputs. Adding type hints will improve code documentation and catch potential type-related bugs early.
Proposed Solution
Add appropriate type hints to functions in the utils directory, focusing on:
- Function parameters
- Return types
- Complex data structures
- Generic types where appropriate
Technical Details
Example of adding type hints:
Before:
def get_cached_data(key, default=None):
if key in cache:
return cache[key]
return default
def calculate_success_rate(solved, total):
if total == 0:
return 0
return (solved / total) * 100After:
from typing import TypeVar, Optional, Dict, Any
T = TypeVar('T')
def get_cached_data(key: str, default: Optional[T] = None) -> Optional[T]:
if key in cache:
return cache[key]
return default
def calculate_success_rate(solved: int, total: int) -> float:
if total == 0:
return 0.0
return (solved / total) * 100.0Target Files
Start with:
core/utils/cache.pyapi/core/utils/cache.py
Required Skills
- Python
- Basic Type Hints Knowledge
- Other: _____
Difficulty Level
- Beginner Friendly
- Intermediate
- Advanced
Estimated Time
- Small (< 2 hours)
- Medium (2-4 hours)
- Large (4-8 hours)
- Extra Large (> 8 hours)
Implementation Checklist
- Review current utility functions
- Add type hints to function parameters
- Add return type hints
- Add type hints for complex data structures
- Add docstrings explaining types
- Run mypy for type checking
- Update documentation
Getting Started
- Install mypy:
pip install mypy- Common type hints to use:
from typing import (
List, Dict, Set, Tuple,
Optional, Union, Any,
TypeVar, Generic
)- Run type checking:
mypy core/utils/cache.pyResources for Learning Type Hints
Tips
- Use Optional[T] for values that could be None
- Use Union[Type1, Type2] for values that could be multiple types
- Use TypeVar for generic type hints
- Add clear docstrings explaining complex types
This is a great first issue for:
- Learning Python type hints
- Understanding code documentation
- Using static type checkers
- Improving code maintainability
Labels: good first issue, enhancement, documentation, python
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededpriority:lowrefactor