Check Python code for type hint completeness and correctness:
Analyzes Python code for type hint completeness and suggests fixes for missing or imprecise annotations.
/plugin marketplace add lwmacct/260112-cc-plugins-study/plugin install python-standards@cc-plugins-studyCheck Python code for type hint completeness and correctness:
Type Hint Checks:
Function Annotations
-> None explicitly)typing module for complex typesCommon Type Patterns
# Basic types
def process(name: str, count: int) -> bool: ...
# Collections
from typing import List, Dict, Set, Tuple
def get_items() -> List[str]: ...
def get_mapping() -> Dict[str, int]: ...
# Optional values
from typing import Optional
def find_user(id: int) -> Optional[User]: ...
# Union types
from typing import Union
def process(data: Union[str, bytes]) -> str: ...
# Use pipe syntax (Python 3.10+)
def process(data: str | bytes) -> str: ...
Advanced Type Patterns
# Callable
from typing import Callable
def apply(func: Callable[[int, int], int]) -> int: ...
# TypeVar for generic functions
from typing import TypeVar
T = TypeVar('T')
def first(items: List[T]) -> T: ...
# Protocol for structural subtyping
from typing import Protocol
class Sized(Protocol):
def __len__(self) -> int: ...
Class Attributes
dataclasses for data-heavy classes@property with type hintsCommon Mistakes
# ❌ Don't use Any when specific type is known
def process(x: Any) -> Any: ...
# ❌ Don't forget return type
def process(x: int): ...
# ❌ Don't use comments for types
def process(x): # type: int
...
# ✅ Use proper type hints
def process(x: int) -> int: ...
Type Checking Tools
mypy for static type checkingpyright or pyre as alternativesOutput Format:
🔴 MISSING: [Function/Class missing type hints]
Location: [file:line]
Fix: [Add proper type hints with example]
🟡 IMPRECISE: [Using Any or generic type]
Location: [file:line]
Why: [Specific type is better for documentation and checking]
Fix: [More precise type hint]
💡 SUGGESTION: [Modern type pattern]
Location: [file:line]
Before: [Old pattern]
After: [Modern alternative]
Check for missing type hints in all public functions and methods.