The OpenAI Python types define a Batch class with a status field:
class Batch(BaseModel):
id: str
# ...
status: Literal[
"validating", "failed", "in_progress", "finalizing", "completed", "expired", "cancelling", "cancelled"
]
"""The current status of the batch."""
I'd like to re-use the Literal[...] type hint from the status field in my own class. Here's an attempt:
from typing import Optional, TypedDict
import openai
class FileStatus(TypedDict):
filename: str
sha256: str
file_id: Optional[str]
batch_id: Optional[str]
batch_status: Optional[openai.types.Batch.status]
# ~~~~~~
# Variable not allowed in type expression Pylance(reportInvalidTypeForm)
What should I use as the type hint for batch_status? I'd prefer to avoid copy/pasting the Literal[...] expression from the OpenAI API if possible.
Literalisn't really a good way to define an enumerated type in the first place.