From 5eb24734d6fa9022c8cf04609531eff1c5577c2f Mon Sep 17 00:00:00 2001 From: montezdesousa Date: Tue, 11 Jul 2023 11:46:02 +0100 Subject: [PATCH] fix prov interface typing --- .../openbb_sdk_core/app/provider_interface.py | 61 ++++++++++--------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/openbb_sdk/openbb_sdk_core/openbb_sdk_core/app/provider_interface.py b/openbb_sdk/openbb_sdk_core/openbb_sdk_core/app/provider_interface.py index ace8c882e4d..892e614c514 100644 --- a/openbb_sdk/openbb_sdk_core/openbb_sdk_core/app/provider_interface.py +++ b/openbb_sdk/openbb_sdk_core/openbb_sdk_core/app/provider_interface.py @@ -290,7 +290,7 @@ class ProviderInterface: @dataclass class StockNews(ProviderChoices): - provider: Literal["benzinga", "polygon", "openbb"] + provider: Literal["benzinga", "polygon"] """ result: Dict = {} @@ -308,35 +308,6 @@ class ProviderInterface: return result - def __merge_data_dc(self, data: Dict) -> Dict[str, StandardData]: - result: Dict = {} - for query_name, dataclasses in data.items(): - standard = dataclasses["standard"] - extra = dataclasses["extra"] - - fields = standard.__fields__.copy() - fields.update(extra.__fields__) - - fields_dict: Dict[str, Tuple[Any, Any]] = {} - for name, field in fields.items(): - fields_dict[name] = ( - field.type_, - Field( - default=field.default, description=field.field_info.description - ), - ) - - class Config(BaseConfig): - extra = Extra.allow - - result[query_name] = create_model( # type: ignore - query_name, - __config__=Config, - **fields_dict, # type: ignore - ) - - return result - def __generate_data_dc( self, ) -> Dict[str, Dict[str, Union[StandardData, ExtraData]]]: @@ -374,6 +345,36 @@ class ProviderInterface: return result + def __merge_data_dc(self, data: Dict[str, Dict[str, Union[StandardData, ExtraData]]]) -> Dict[str, BaseModel]: + """Merge standard data with extra data into a single BaseModel""" + result: Dict = {} + for query_name, dataclasses in data.items(): + standard = dataclasses["standard"] + extra = dataclasses["extra"] + + fields = standard.__fields__.copy() + fields.update(extra.__fields__) + + fields_dict: Dict[str, Tuple[Any, Any]] = {} + for name, field in fields.items(): + fields_dict[name] = ( + field.type_, + Field( + default=field.default, description=field.field_info.description + ), + ) + + class Config(BaseConfig): + extra = Extra.allow + + result[query_name] = create_model( # type: ignore + query_name, + __config__=Config, + **fields_dict, # type: ignore + ) + + return result + __provider_interface = ProviderInterface()