mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-03 07:51:49 +00:00
remove return type stuff
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Literal, Optional, TypeVar
|
||||
from typing import Any, Dict, List, Literal, Optional
|
||||
|
||||
from openbb_provider.abstract.fetcher import Fetcher
|
||||
from openbb_provider.helpers import get_querystring
|
||||
@@ -104,9 +104,6 @@ class BenzingaGlobalNewsFetcher(
|
||||
BenzingaGlobalNewsData,
|
||||
]
|
||||
):
|
||||
T = TypeVar("T")
|
||||
generic_return_type = List[T]
|
||||
|
||||
@staticmethod
|
||||
def transform_query(params: Dict[str, Any]) -> BenzingaGlobalNewsQueryParams:
|
||||
return BenzingaGlobalNewsQueryParams(**params)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Literal, Optional, TypeVar
|
||||
from typing import Any, Dict, List, Literal, Optional
|
||||
|
||||
from openbb_provider.abstract.fetcher import Fetcher
|
||||
from openbb_provider.helpers import get_querystring
|
||||
@@ -100,9 +100,6 @@ class BenzingaStockNewsFetcher(
|
||||
BenzingaStockNewsData,
|
||||
]
|
||||
):
|
||||
T = TypeVar("T")
|
||||
generic_return_type = List[T]
|
||||
|
||||
@staticmethod
|
||||
def transform_query(params: Dict[str, Any]) -> BenzingaStockNewsQueryParams:
|
||||
return BenzingaStockNewsQueryParams(**params)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, TypeVar
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from openbb_provider.abstract.data import Data
|
||||
from openbb_provider.abstract.fetcher import Fetcher
|
||||
@@ -40,9 +40,6 @@ class FMPStockNewsFetcher(
|
||||
FMPStockNewsData,
|
||||
]
|
||||
):
|
||||
T = TypeVar("T")
|
||||
generic_return_type = List[T]
|
||||
|
||||
@staticmethod
|
||||
def transform_query(params: Dict[str, Any]) -> FMPStockNewsQueryParams:
|
||||
return FMPStockNewsQueryParams(**params)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""FRED CPI Fetcher."""
|
||||
|
||||
|
||||
from typing import Any, Dict, List, Optional, TypeVar
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from openbb_fred.utils.fred_base import Fred
|
||||
from openbb_fred.utils.fred_helpers import all_cpi_options
|
||||
@@ -22,9 +22,6 @@ class FREDCPIData(CPIData):
|
||||
class FREDCPIFetcher(Fetcher[CPIQueryParams, CPIData, FREDCPIQueryParams, FREDCPIData]):
|
||||
"""FRED CPI Fetcher."""
|
||||
|
||||
T = TypeVar("T")
|
||||
generic_return_type = Dict[str, List[T]]
|
||||
|
||||
@staticmethod
|
||||
def transform_query(params: Dict[str, Any]) -> FREDCPIQueryParams:
|
||||
return FREDCPIQueryParams(**params)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Literal, Optional, TypeVar
|
||||
from typing import Any, Dict, List, Literal, Optional
|
||||
|
||||
from openbb_provider.abstract.data import Data
|
||||
from openbb_provider.abstract.fetcher import Fetcher
|
||||
@@ -89,9 +89,6 @@ class PolygonStockNewsFetcher(
|
||||
PolygonStockNewsData,
|
||||
]
|
||||
):
|
||||
T = TypeVar("T")
|
||||
generic_return_type = List[T]
|
||||
|
||||
@staticmethod
|
||||
def transform_query(params: Dict[str, Any]) -> PolygonStockNewsQueryParams:
|
||||
return PolygonStockNewsQueryParams(**params)
|
||||
|
||||
@@ -84,7 +84,7 @@ class ProviderInterface:
|
||||
self._model_providers_map = self._generate_model_providers_dc(self._map)
|
||||
self._params = self._generate_params_dc(self._map)
|
||||
self._data = self._generate_data_dc(self._map)
|
||||
self._merged_return_model = self._merge_return_model(self._map, self._data)
|
||||
self._merged_return_model = self._merge_return_model(self._data)
|
||||
|
||||
self._providers_literal = self._get_provider_literal(
|
||||
self._registry_map.available_providers
|
||||
@@ -398,7 +398,6 @@ class ProviderInterface:
|
||||
|
||||
def _merge_return_model(
|
||||
self,
|
||||
map_: MapType,
|
||||
data: Dict[str, Dict[str, Union[StandardData, ExtraData]]],
|
||||
) -> Dict[str, Type[BaseModel]]:
|
||||
"""Merge standard data with extra data into a single BaseModel to be injected as FastAPI dependency."""
|
||||
@@ -430,12 +429,9 @@ class ProviderInterface:
|
||||
**fields_dict, # type: ignore
|
||||
)
|
||||
|
||||
ReturnType = map_[model_name]["openbb"]["ReturnType"]
|
||||
n_params = len(getattr(ReturnType, "__parameters__", ()))
|
||||
if n_params:
|
||||
result[model_name] = ReturnType[tuple([ReturnModel] * n_params)] # type: ignore
|
||||
else:
|
||||
result[model_name] = ReturnModel
|
||||
# TODO: If we want to support multiple return schemas, we need
|
||||
# to change this `List` to the schema type
|
||||
result[model_name] = List[ReturnModel] # type: ignore
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -76,9 +76,3 @@ class Fetcher(
|
||||
"""Get the type of the provider data."""
|
||||
# pylint: disable=E1101
|
||||
return self.__orig_bases__[0].__args__[3]
|
||||
|
||||
# @property
|
||||
# @abstractmethod
|
||||
# def generic_return_type(self):
|
||||
# """Get the type of the generic return."""
|
||||
# raise NotImplementedError
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Dict, List, Literal, Optional, TypeVar, Union
|
||||
from typing import Any, Dict, List, Literal, Optional
|
||||
|
||||
from openbb_provider.abstract.fetcher import Fetcher
|
||||
from openbb_provider.registry import Registry, RegistryLoader
|
||||
@@ -57,24 +57,19 @@ class RegistryMap:
|
||||
f = fetcher()
|
||||
standard_query, extra_query = self.extract_info(f, "query_params")
|
||||
standard_data, extra_data = self.extract_info(f, "data")
|
||||
return_type = self.extract_return_type(f)
|
||||
|
||||
if model_name not in map_:
|
||||
map_[model_name] = {}
|
||||
map_[model_name]["openbb"] = {
|
||||
"QueryParams": standard_query,
|
||||
"Data": standard_data,
|
||||
"ReturnType": None,
|
||||
}
|
||||
|
||||
map_[model_name][p] = {
|
||||
"QueryParams": extra_query,
|
||||
"Data": extra_data,
|
||||
"ReturnType": return_type,
|
||||
}
|
||||
|
||||
map_ = self.fill_standard_return_type(map_)
|
||||
|
||||
return map_
|
||||
|
||||
def _get_models(self, map_: MapType) -> List[str]:
|
||||
@@ -100,29 +95,3 @@ class RegistryMap:
|
||||
extra_info["fields"][name] = field
|
||||
|
||||
return standard_info, extra_info
|
||||
|
||||
@staticmethod
|
||||
def extract_return_type(fetcher: Fetcher):
|
||||
"""Extract return info from fetcher."""
|
||||
return getattr(fetcher, "generic_return_type", None)
|
||||
|
||||
@staticmethod
|
||||
def fill_standard_return_type(map_: MapType) -> MapType:
|
||||
"""Fill standard return type."""
|
||||
|
||||
T = TypeVar("T")
|
||||
GenericDataType = Union[T, List[T], Dict[str, T]]
|
||||
|
||||
for model_name, providers in map_.items():
|
||||
types_list = []
|
||||
for info in providers.values():
|
||||
ret = info["ReturnType"]
|
||||
if ret:
|
||||
types_list.append(ret)
|
||||
|
||||
if types_list:
|
||||
map_[model_name]["openbb"]["ReturnType"] = Union[tuple(types_list)] # type: ignore
|
||||
else:
|
||||
map_[model_name]["openbb"]["ReturnType"] = GenericDataType
|
||||
|
||||
return map_
|
||||
|
||||
Reference in New Issue
Block a user