MyPy improvements

This commit is contained in:
Igor Radovanovic
2023-08-18 15:52:29 +02:00
parent 379ece5dd2
commit e0776b4e55
25 changed files with 70 additions and 85 deletions

View File

@@ -116,8 +116,6 @@ class FMPBalanceSheetFetcher(
api_key = credentials.get("fmp_api_key") if credentials else ""
query.period = "annual" if query.period == "annually" else "quarter"
url = create_url(
3, f"balance-sheet-statement/{query.symbol}", api_key, query, ["symbol"]
)

View File

@@ -100,11 +100,8 @@ class FMPCashFlowStatementFetcher(
**kwargs: Any,
) -> List[Dict]:
"""Return the raw data from the FMP endpoint."""
api_key = credentials.get("fmp_api_key") if credentials else ""
query.period = "annual" if query.period == "annually" else "quarter"
url = create_url(
3, f"cash-flow-statement/{query.symbol}", api_key, query, ["symbol"]
)

View File

@@ -108,14 +108,9 @@ class FMPFinancialRatiosFetcher(
**kwargs: Any,
) -> List[Dict]:
"""Return the raw data from the FMP endpoint."""
api_key = credentials.get("fmp_api_key") if credentials else ""
query.period = (
"annual" if query.period == "annually" else "quarter" # mypy: ignore
)
base_url = "https://financialmodelingprep.com/api/v3"
data: List[Dict] = []
def multiple_symbols(symbol: str, data: List[Dict]) -> None:

View File

@@ -101,7 +101,6 @@ class FMPIncomeStatementFetcher(
api_key = credentials.get("fmp_api_key") if credentials else ""
query.period = "annual" if query.period == "annually" else "quarter"
symbol = query.symbol or query.cik
base_url = "https://financialmodelingprep.com/api/v3"

View File

@@ -86,8 +86,6 @@ class FMPIncomeStatementGrowthFetcher(
api_key = credentials.get("fmp_api_key") if credentials else ""
query.period = "annual" if query.period == "annually" else "quarter"
url = create_url(
3, f"income-statement-growth/{query.symbol}", api_key, query, ["symbol"]
)

View File

@@ -112,8 +112,6 @@ class FMPKeyMetricsFetcher(
api_key = credentials.get("fmp_api_key") if credentials else ""
query.period = "annual" if query.period == "annually" else "quarter"
data: List[Dict] = []
def multiple_symbols(symbol: str, data: List[Dict]) -> None:

View File

@@ -51,11 +51,8 @@ class FMPRevenueBusinessLineFetcher(
**kwargs: Any,
) -> List[Dict]:
"""Return the raw data from the FMP endpoint."""
api_key = credentials.get("fmp_api_key") if credentials else ""
query.period = "annual" if query.period == "annually" else "quarter"
url = create_url(4, "revenue-product-segmentation", api_key, query)
data = get_data(url, **kwargs)

View File

@@ -51,11 +51,8 @@ class FMPRevenueGeographicFetcher(
**kwargs: Any,
) -> List[Dict]:
"""Return the raw data from the FMP endpoint."""
api_key = credentials.get("fmp_api_key") if credentials else ""
query.period = "annual" if query.period == "annually" else "quarter"
url = create_url(4, "revenue-geographic-segmentation", api_key, query)
data = get_data(url, **kwargs)

View File

@@ -52,8 +52,6 @@ class PolygonBalanceSheetFetcher(
) -> dict:
api_key = credentials.get("polygon_api_key") if credentials else ""
query.period = "annual" if query.period == "annually" else "quarter"
base_url = "https://api.polygon.io/vX/reference/financials"
query_string = get_querystring(query.dict(by_alias=True), [])
request_url = f"{base_url}?{query_string}&apiKey={api_key}"

View File

@@ -46,8 +46,6 @@ class PolygonCashFlowStatementFetcher(
) -> dict:
api_key = credentials.get("polygon_api_key") if credentials else ""
query.period = "annual" if query.period == "annually" else "quarter"
base_url = "https://api.polygon.io/vX/reference/financials"
query_string = get_querystring(query.dict(by_alias=True), [])
request_url = f"{base_url}?{query_string}&apiKey={api_key}"

View File

@@ -63,10 +63,16 @@ class PolygonForexPairsData(ForexPairsData):
market: str = Field(description="The name of the trading market. Always 'fx'.")
locale: str = Field(description="The locale of the currency pair.")
currency_symbol: str = Field(description="The symbol of the quote currency.")
currency_name: str = Field(description="The name of the quote currency.")
base_currency_symbol: str = Field(description="The symbol of the base currency.")
base_currency_name: str = Field(description="The name of the base currency.")
currency_symbol: Optional[str] = Field(
description="The symbol of the quote currency."
)
currency_name: Optional[str] = Field(description="The name of the quote currency.")
base_currency_symbol: Optional[str] = Field(
description="The symbol of the base currency."
)
base_currency_name: Optional[str] = Field(
description="The name of the base currency."
)
last_updated_utc: datetime = Field(description="The last updated timestamp in UTC.")
delisted_utc: Optional[datetime] = Field(
description="The delisted timestamp in UTC."
@@ -108,7 +114,7 @@ class PolygonForexPairsFetcher(
query: PolygonForexPairsQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> dict:
) -> List[dict]:
"""Extract the data from the Polygon API."""
api_key = credentials.get("polygon_api_key") if credentials else ""
@@ -135,7 +141,12 @@ class PolygonForexPairsFetcher(
)
if data["status"] == "OK":
all_data.extend(data["results"])
results = data.get("results")
if not isinstance(results, list):
raise ValueError(
"Expected 'results' to be a list, got something else."
)
all_data.extend(results)
elif data["status"] == "ERROR":
raise UserWarning(data["error"])
@@ -146,7 +157,7 @@ class PolygonForexPairsFetcher(
@staticmethod
def transform_data(
data: dict,
data: List[dict],
) -> List[PolygonForexPairsData]:
"""Transform the data into a list of PolygonForexPairsData."""

View File

@@ -72,8 +72,6 @@ class PolygonIncomeStatementFetcher(
) -> dict:
api_key = credentials.get("polygon_api_key") if credentials else ""
query.period = "annual" if query.period == "annually" else "quarter"
base_url = "https://api.polygon.io/vX/reference/financials"
query_string = get_querystring(query.dict(by_alias=True), [])
request_url = f"{base_url}?{query_string}&apiKey={api_key}"

View File

@@ -81,10 +81,10 @@ class PolygonStockEODFetcher(
query: PolygonStockEODQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[PolygonStockEODData]:
) -> List[dict]:
api_key = credentials.get("polygon_api_key") if credentials else ""
data = []
data: list = []
def multiple_symbols(symbol: str, data: List[PolygonStockEODData]) -> None:
request_url = (
@@ -111,5 +111,5 @@ class PolygonStockEODFetcher(
return data
@staticmethod
def transform_data(data: List[PolygonStockEODData]) -> List[StockEODData]:
return [StockEODData.parse_obj(d.dict()) for d in data]
def transform_data(data: List[dict]) -> List[PolygonStockEODData]:
return [PolygonStockEODData.parse_obj(d) for d in data]

View File

@@ -1,7 +1,10 @@
"""yfinance helpers module."""
from datetime import datetime
from datetime import (
date as dateType,
datetime,
)
from pathlib import Path
from typing import Optional
@@ -18,7 +21,7 @@ def get_futures_data() -> pd.DataFrame:
return pd.read_csv(Path(__file__).resolve().parent / "futures.csv")
def get_futures_curve(symbol: str, date: Optional[str]) -> pd.DataFrame:
def get_futures_curve(symbol: str, date: Optional[dateType]) -> pd.DataFrame:
"""Get the futures curve for a given symbol.
Parameters
@@ -33,7 +36,6 @@ def get_futures_curve(symbol: str, date: Optional[str]) -> pd.DataFrame:
pd.DataFrame
DataFrame with futures curve
"""
futures_data = get_futures_data()
exchange = futures_data[futures_data["Ticker"] == symbol]["Exchange"].values[0]
today = datetime.today()

View File

@@ -1,7 +1,6 @@
### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###
from openbb_core.app.static.container import Container

View File

@@ -316,7 +316,7 @@ class CLASS_economy(Container):
OpenBBCustomParameter(description="The data units."),
] = "growth_same",
frequency: Annotated[
Literal["monthly", "quarterly", "annual"],
Literal["monthly", "quarter", "annual"],
OpenBBCustomParameter(description="The data time frequency."),
] = "monthly",
harmonized: Annotated[
@@ -349,7 +349,7 @@ class CLASS_economy(Container):
The country or countries to get data.
units : Literal['growth_previous', 'growth_same', 'index_2015']
The data units.
frequency : Literal['monthly', 'quarterly', 'annual']
frequency : Literal['monthly', 'quarter', 'annual']
The data time frequency.
harmonized : bool
Whether you wish to obtain harmonized data.

View File

@@ -43,9 +43,9 @@ class CLASS_stocks_fa(Container):
OpenBBCustomParameter(description="Symbol to get data for."),
],
period: Annotated[
Literal["annually", "quarterly"],
Literal["annual", "quarter"],
OpenBBCustomParameter(description="Period of the data to return."),
] = "annually",
] = "annual",
limit: Annotated[
Optional[pydantic.types.NonNegativeInt],
OpenBBCustomParameter(description="The number of data entries to return."),
@@ -60,7 +60,7 @@ class CLASS_stocks_fa(Container):
----------
symbol : Union[str, List[str]]
Symbol to get data for.
period : Literal['annually', 'quarterly']
period : Literal['annual', 'quarter']
Period of the data to return.
limit : Optional[pydantic.types.NonNegativeInt]
The number of data entries to return.
@@ -499,9 +499,9 @@ class CLASS_stocks_fa(Container):
OpenBBCustomParameter(description="Symbol to get data for."),
],
period: Annotated[
Literal["annually", "quarterly"],
Literal["annual", "quarter"],
OpenBBCustomParameter(description="Period of the data to return."),
] = "annually",
] = "annual",
limit: Annotated[
Optional[pydantic.types.NonNegativeInt],
OpenBBCustomParameter(description="The number of data entries to return."),
@@ -516,7 +516,7 @@ class CLASS_stocks_fa(Container):
----------
symbol : Union[str, List[str]]
Symbol to get data for.
period : Literal['annually', 'quarterly']
period : Literal['annual', 'quarter']
Period of the data to return.
limit : Optional[pydantic.types.NonNegativeInt]
The number of data entries to return.
@@ -1316,9 +1316,9 @@ class CLASS_stocks_fa(Container):
OpenBBCustomParameter(description="Symbol to get data for."),
],
period: Annotated[
Literal["annually", "quarterly"],
Literal["annual", "quarter"],
OpenBBCustomParameter(description="Period of the data to return."),
] = "annually",
] = "annual",
limit: Annotated[
int,
OpenBBCustomParameter(description="The number of data entries to return."),
@@ -1333,7 +1333,7 @@ class CLASS_stocks_fa(Container):
----------
symbol : Union[str, List[str]]
Symbol to get data for.
period : Literal['annually', 'quarterly']
period : Literal['annual', 'quarter']
Period of the data to return.
limit : int
The number of data entries to return.
@@ -1522,9 +1522,9 @@ class CLASS_stocks_fa(Container):
OpenBBCustomParameter(description="Symbol to get data for."),
],
period: Annotated[
Literal["annually", "quarterly"],
Literal["annual", "quarter"],
OpenBBCustomParameter(description="Period of the data to return."),
] = "annually",
] = "annual",
limit: Annotated[
Optional[pydantic.types.NonNegativeInt],
OpenBBCustomParameter(description="The number of data entries to return."),
@@ -1539,7 +1539,7 @@ class CLASS_stocks_fa(Container):
----------
symbol : Union[str, List[str]]
Symbol to get data for.
period : Literal['annually', 'quarterly']
period : Literal['annual', 'quarter']
Period of the data to return.
limit : Optional[pydantic.types.NonNegativeInt]
The number of data entries to return.
@@ -1724,9 +1724,9 @@ class CLASS_stocks_fa(Container):
OpenBBCustomParameter(description="The number of data entries to return."),
] = 10,
period: Annotated[
Literal["annually", "quarterly"],
Literal["annual", "quarter"],
OpenBBCustomParameter(description="Period of the data to return."),
] = "annually",
] = "annual",
chart: bool = False,
provider: Optional[Literal["fmp"]] = None,
**kwargs
@@ -1739,7 +1739,7 @@ class CLASS_stocks_fa(Container):
Symbol to get data for.
limit : int
The number of data entries to return.
period : Literal['annually', 'quarterly']
period : Literal['annual', 'quarter']
Period of the data to return.
chart : bool
Whether to create a chart or not, by default False.
@@ -2155,9 +2155,9 @@ class CLASS_stocks_fa(Container):
OpenBBCustomParameter(description="Symbol to get data for."),
],
period: Annotated[
Literal["annually", "quarterly"],
Literal["annual", "quarter"],
OpenBBCustomParameter(description="Period of the data to return."),
] = "annually",
] = "annual",
limit: Annotated[
Optional[int],
OpenBBCustomParameter(description="The number of data entries to return."),
@@ -2172,7 +2172,7 @@ class CLASS_stocks_fa(Container):
----------
symbol : Union[str, List[str]]
Symbol to get data for.
period : Literal['annually', 'quarterly']
period : Literal['annual', 'quarter']
Period of the data to return.
limit : Optional[int]
The number of data entries to return.
@@ -2919,9 +2919,9 @@ class CLASS_stocks_fa(Container):
OpenBBCustomParameter(description="Symbol to get data for."),
],
period: Annotated[
Literal["annually", "quarterly"],
Literal["annual", "quarter"],
OpenBBCustomParameter(description="Period of the data to return."),
] = "annually",
] = "annual",
limit: Annotated[
Optional[pydantic.types.NonNegativeInt],
OpenBBCustomParameter(description="The number of data entries to return."),
@@ -2936,7 +2936,7 @@ class CLASS_stocks_fa(Container):
----------
symbol : Union[str, List[str]]
Symbol to get data for.
period : Literal['annually', 'quarterly']
period : Literal['annual', 'quarter']
Period of the data to return.
limit : Optional[pydantic.types.NonNegativeInt]
The number of data entries to return.
@@ -3125,9 +3125,9 @@ class CLASS_stocks_fa(Container):
OpenBBCustomParameter(description="Symbol to get data for."),
],
period: Annotated[
Literal["annually", "quarterly"],
Literal["annual", "quarter"],
OpenBBCustomParameter(description="Period of the data to return."),
] = "annually",
] = "annual",
structure: Annotated[
Literal["hierarchical", "flat"],
OpenBBCustomParameter(description="Structure of the returned data."),
@@ -3142,7 +3142,7 @@ class CLASS_stocks_fa(Container):
----------
symbol : Union[str, List[str]]
Symbol to get data for.
period : Literal['annually', 'quarterly']
period : Literal['annual', 'quarter']
Period of the data to return.
structure : Literal['hierarchical', 'flat']
Structure of the returned data.
@@ -3213,9 +3213,9 @@ class CLASS_stocks_fa(Container):
OpenBBCustomParameter(description="Symbol to get data for."),
],
period: Annotated[
Literal["annually", "quarterly"],
Literal["annual", "quarter"],
OpenBBCustomParameter(description="Period of the data to return."),
] = "annually",
] = "annual",
structure: Annotated[
Literal["hierarchical", "flat"],
OpenBBCustomParameter(description="Structure of the returned data."),
@@ -3230,7 +3230,7 @@ class CLASS_stocks_fa(Container):
----------
symbol : Union[str, List[str]]
Symbol to get data for.
period : Literal['annually', 'quarterly']
period : Literal['annual', 'quarter']
Period of the data to return.
structure : Literal['hierarchical', 'flat']
Structure of the returned data.

View File

@@ -15,8 +15,8 @@ from openbb_provider.utils.descriptions import QUERY_DESCRIPTIONS
class AnalystEstimatesQueryParams(QueryParams, BaseSymbol):
"""Analyst Estimates query."""
period: Literal["quarterly", "annually"] = Field(
default="annually", description=QUERY_DESCRIPTIONS.get("period", "")
period: Literal["quarter", "annual"] = Field(
default="annual", description=QUERY_DESCRIPTIONS.get("period", "")
)
limit: int = Field(default=30, description=QUERY_DESCRIPTIONS.get("limit", ""))

View File

@@ -23,8 +23,8 @@ class BaseSymbol(BaseModel):
class FinancialStatementQueryParams(QueryParams, BaseSymbol):
"""Base model for financial statement query params."""
period: Literal["annually", "quarterly"] = Field(
default="annually", description=QUERY_DESCRIPTIONS.get("period", "")
period: Literal["annual", "quarter"] = Field(
default="annual", description=QUERY_DESCRIPTIONS.get("period", "")
)
limit: Optional[NonNegativeInt] = Field(
default=12, description=QUERY_DESCRIPTIONS.get("limit", "")

View File

@@ -62,7 +62,7 @@ CPI_COUNTRIES = Literal[
CPI_UNITS = Literal["growth_previous", "growth_same", "index_2015"]
CPI_FREQUENCY = Literal["monthly", "quarterly", "annual"]
CPI_FREQUENCY = Literal["monthly", "quarter", "annual"]
class CPIQueryParams(QueryParams):

View File

@@ -22,7 +22,7 @@ class IncomeStatementData(Data):
date: dateType = Field(description="Date of the income statement.")
symbol: str = Field(description="Symbol of the company.")
cik: Optional[int] = Field(description="Central Index Key.")
cik: Optional[str] = Field(description="Central Index Key.")
currency: Optional[str] = Field(description="Reporting currency.")
filing_date: Optional[dateType] = Field(description="Filling date.")

View File

@@ -16,8 +16,8 @@ class IncomeStatementGrowthQueryParams(QueryParams, BaseSymbol):
"""Income Statement Growth Query."""
limit: int = Field(default=10, description=QUERY_DESCRIPTIONS.get("limit", ""))
period: Literal["annually", "quarterly"] = Field(
default="annually", description=QUERY_DESCRIPTIONS.get("period", "")
period: Literal["annual", "quarter"] = Field(
default="annual", description=QUERY_DESCRIPTIONS.get("period", "")
)

View File

@@ -15,8 +15,8 @@ from openbb_provider.utils.descriptions import DATA_DESCRIPTIONS, QUERY_DESCRIPT
class KeyMetricsQueryParams(QueryParams, BaseSymbol):
"""Key Metrics Query."""
period: Literal["annually", "quarterly"] = Field(
default="annually", description=QUERY_DESCRIPTIONS.get("period", "")
period: Literal["annual", "quarter"] = Field(
default="annual", description=QUERY_DESCRIPTIONS.get("period", "")
)
limit: Optional[int] = Field(
default=100, description=QUERY_DESCRIPTIONS.get("limit", "")

View File

@@ -15,8 +15,8 @@ from openbb_provider.utils.descriptions import DATA_DESCRIPTIONS, QUERY_DESCRIPT
class RevenueBusinessLineQueryParams(QueryParams, BaseSymbol):
"""Revenue Business Line Query."""
period: Literal["quarterly", "annually"] = Field(
default="annually", description=QUERY_DESCRIPTIONS.get("period", "")
period: Literal["quarter", "annual"] = Field(
default="annual", description=QUERY_DESCRIPTIONS.get("period", "")
)
structure: Literal["hierarchical", "flat"] = Field(
default="flat", description="Structure of the returned data."

View File

@@ -15,8 +15,8 @@ from openbb_provider.utils.descriptions import DATA_DESCRIPTIONS, QUERY_DESCRIPT
class RevenueGeographicQueryParams(QueryParams, BaseSymbol):
"""Revenue by Geographic Segments Query."""
period: Literal["quarterly", "annually"] = Field(
default="annually", description=QUERY_DESCRIPTIONS.get("period", "")
period: Literal["quarter", "annual"] = Field(
default="annual", description=QUERY_DESCRIPTIONS.get("period", "")
)
structure: Literal["hierarchical", "flat"] = Field(
default="flat", description="Structure of the returned data."