Priority: Low (Enhancement)
Issue
The API configuration dictionary uses generic dict[str, Any] types, which doesn't provide type safety or IDE autocomplete for API endpoint definitions.
Current Code
ensembl_api_table: dict[str, Any] = {
"getArchiveById": {
"doc": "Uses the given identifier to return its latest version",
"url": "/archive/id/{{id}}",
"method": "GET",
"content_type": "application/json",
},
# ... many more
}
Recommendation
Create TypedDict for better type safety:
from typing import TypedDict, Literal, NotRequired
class APIEndpoint(TypedDict):
"""Definition of an Ensembl REST API endpoint."""
doc: str
url: str
method: Literal["GET", "POST"]
content_type: str
post_parameters: NotRequired[list[str]] # Only for POST endpoints
ensembl_api_table: dict[str, APIEndpoint] = {
"getArchiveById": {
"doc": "Uses the given identifier to return its latest version",
"url": "/archive/id/{{id}}",
"method": "GET",
"content_type": "application/json",
},
# ... rest
}
Benefits
- Better IDE autocomplete
- Catch errors at type-check time
- Self-documenting API structure
- Easier for contributors to understand schema
Files to Update
pyensemblrest/ensembl_config.py - Add TypedDict and update type hints
pyensemblrest/ensemblrest.py - Update method signatures
Testing
- Run mypy:
poetry run mypy pyensemblrest/
- Ensure no type errors introduced
- Verify IDE autocomplete works
Notes
Requires Python 3.10+ for NotRequired (already minimum version)
Priority: Low (Enhancement)
Issue
The API configuration dictionary uses generic
dict[str, Any]types, which doesn't provide type safety or IDE autocomplete for API endpoint definitions.Current Code
Recommendation
Create TypedDict for better type safety:
Benefits
Files to Update
pyensemblrest/ensembl_config.py- Add TypedDict and update type hintspyensemblrest/ensemblrest.py- Update method signaturesTesting
poetry run mypy pyensemblrest/Notes
Requires Python 3.10+ for
NotRequired(already minimum version)