Description
As identified in PR #32 review, some Any types in the codebase (particularly in method_factory.py) could be replaced with more specific type annotations.
Current State
- Dynamic method generation uses
Any for flexibility
- Type checking is less strict in these areas
- IDE support could be improved
Areas to Improve
1. Method Factory
Current:
def create_method(
query_info: QueryInfo,
client: Any, # Could be more specific
method_name: str
) -> Callable[..., Any]: # Return type could be more specific
Improved:
from typing import Protocol, TypeVar
class GraphQLClient(Protocol):
async def execute(self, query: str, variables: dict) -> Any: ...
T = TypeVar('T')
def create_method(
query_info: QueryInfo,
client: GraphQLClient,
method_name: str
) -> Callable[..., Awaitable[T]]:
2. Parameter Builders
- Use TypedDict for parameter dictionaries
- Use Literal types for known string values
- Use Protocol for duck-typed interfaces
3. Generated Code Integration
- Create Protocol definitions for generated types
- Use TYPE_CHECKING imports effectively
Benefits
- Better IDE autocomplete
- Stricter type checking
- Clearer API contracts
- Improved developer experience
Implementation Strategy
- Start with public API surface
- Use Protocols for structural typing
- Gradually tighten internal types
- Ensure backward compatibility
Tools to Use
mypy --strict for validation
pyright for additional checking
typing_extensions for backward compatibility
References
Description
As identified in PR #32 review, some
Anytypes in the codebase (particularly in method_factory.py) could be replaced with more specific type annotations.Current State
Anyfor flexibilityAreas to Improve
1. Method Factory
Current:
Improved:
2. Parameter Builders
3. Generated Code Integration
Benefits
Implementation Strategy
Tools to Use
mypy --strictfor validationpyrightfor additional checkingtyping_extensionsfor backward compatibilityReferences