I have some data coming in that could look like
{"cloud_url": "https://example.com/file.txt", "filetype": "txt"}
or it could look like
{"local_filepath": "./file.csv", "filetype": "csv", "delimeter": ","}
for my typing I currently have
from typing import Literal, TypedDict
class _FileLocal(TypedDict):
local_filepath: str
class _FileCloud(TypedDict):
cloud_url: str
_FileCloudOrLocal = _FileLocal | _FileCloud
class _FileTextProcess(_FileCloudOrLocal):
filetype: Literal['txt']
class _FileCSVProcess(_FileCloudOrLocal):
filetype: Literal['csv']
delimeter: str
FileProcess = _FileTextProcess | _FileCSVProcess
the issue with this version is that _FileTextProcess can't inherit from a union (a class has to inherit from a class)
how can I specify that local_filepath or cloud_url but not both must be supplied
my current workaround is to create a class for each possible combination, but obviously this isn't feasible for anything much more complex than this