A couple TypedDict classes were added to the Python SDK recently in c656de5. Namely:
MarketFetchParams
EventFetchParams
We should update the signatures of related methods to support these new classes. (Which will also prevent static analyzers from complaining when the appropriate TypedDict is passed to these methods.)
Consider the current signature of Exchange.fetch_market:
def fetch_market(self, params: Optional[dict] = None, **kwargs) -> UnifiedMarket: ...
There are several potential solutions; I outline a few below.
-
We could change the signature to
def fetch_market(self, params: Mapping | None = None, **kwargs) -> UnifiedMarket: ...
which would allow arguments of type dict, Mapping, or TypedDict (and, of course, NoneType).
-
Although Mapping is probably too permissive. I.e., we might as well force clients to use MarketFetchParams.
def fetch_market(self, params: MarketFetchParams | None = None, **kwargs) -> UnifiedMarket: ...
But removing arbitrary dict support would break backward compatibility.
-
Or if we want to keep the legacy Optional[] syntax for now:
def fetch_market(self, params: Optional[Mapping] = None, **kwargs) -> UnifiedMarket: ...
-
If we need to keep dict in the signature for forward compatibility, then we could update the signature to
def fetch_market(self, params: Optional[Union[MarketFetchParams, dict] = None, **kwargs) -> UnifiedMarket: ...
-
For the above options, handling **kwargs will require a bit of finesse in the implementation. We could alternatively consolidate params and **kwargs into a single parameter.
def fetch_market(self, **kwargs: Unpack[MarketFetchParams]) -> UnifiedMarket: ...
but this would require bumping the minimum Python version from 3.8 to 3.11, which I acknowledge is quite a large jump. But noting this solution anyway to keep in mind for the future.
A couple
TypedDictclasses were added to the Python SDK recently in c656de5. Namely:MarketFetchParamsEventFetchParamsWe should update the signatures of related methods to support these new classes. (Which will also prevent static analyzers from complaining when the appropriate
TypedDictis passed to these methods.)Consider the current signature of
Exchange.fetch_market:There are several potential solutions; I outline a few below.
We could change the signature to
which would allow arguments of type
dict,Mapping, orTypedDict(and, of course,NoneType).Although
Mappingis probably too permissive. I.e., we might as well force clients to useMarketFetchParams.But removing arbitrary
dictsupport would break backward compatibility.Or if we want to keep the legacy
Optional[]syntax for now:If we need to keep
dictin the signature for forward compatibility, then we could update the signature toFor the above options, handling
**kwargswill require a bit of finesse in the implementation. We could alternatively consolidateparamsand**kwargsinto a single parameter.but this would require bumping the minimum Python version from 3.8 to 3.11, which I acknowledge is quite a large jump. But noting this solution anyway to keep in mind for the future.