Code ReviewElementary~15 min
Review: Proper Use of Type Hints
pythontype-hintstypingmypy
Code Review Task
Please review the following Python code.
Background
This code is a set of functions that process user data. Using type hints is expected to improve code readability and maintainability.
Review Aspects
- Appropriateness of type hints
- Return value type annotations
- Optional type usage
- Type accuracy
Your Answer
user_processor.pypython
from typing import Dict, Any def process_user(user_data): """Process user data and return formatted result""" return { "name": user_data.get("name", "Unknown"), "email": user_data.get("email", ""), "active": user_data.get("active", True) } def get_user_email(user_data: Dict[str, Any]): """Get user email if valid, otherwise None""" email = user_data.get("email") if email and "@" in email: return email return None def filter_active_users(users: list): """Return list of active user names""" return [u["name"] for u in users if u.get("active", False)]行番号をクリックしてコメントを追加(Shift+クリックで範囲選択)
Minimum 100 characters required
Add comments and enter at least 100 characters in the summary
Model Answer
Submit your answer or click "Show" to view the model answer.