mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
[BugFix] - Fix pylint possibly-used-before-assignment (#6484)
* fix: comply w/ possibly used before assignment * remove disabe from .pylintrc * remove reset test * remove reset test * fix: update missing keys message
This commit is contained in:
2
.pylintrc
vendored
2
.pylintrc
vendored
@@ -54,7 +54,7 @@ confidence=
|
||||
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
|
||||
# disable=too-many-instance-attributes,len-as-condition,too-few-public-methods,anomalous-backslash-in-string,no-else-return,simplifiable-if-statement,too-many-arguments,duplicate-code,no-name-in-module,no-member,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,missing-docstring,invalid-name,bad-whitespace,consider-using-enumerate,unexpected-keyword-arg
|
||||
|
||||
disable=useless-return,missing-docstring,invalid-name,import-error,broad-except,unnecessary-lambda,missing-timeout,duplicate-code,consider-using-generator,unbalanced-tuple-unpacking,use-list-literal,no-name-in-module,use-sequence-for-iteration,use-dict-literal,unspecified-encoding,unsubscriptable-object,broad-exception-raised,possibly-used-before-assignment
|
||||
disable=useless-return,missing-docstring,invalid-name,import-error,broad-except,unnecessary-lambda,missing-timeout,duplicate-code,consider-using-generator,unbalanced-tuple-unpacking,use-list-literal,no-name-in-module,use-sequence-for-iteration,use-dict-literal,unspecified-encoding,unsubscriptable-object,broad-exception-raised
|
||||
|
||||
# Enable the message, report, category or checker with the given id(s). You can
|
||||
# either give multiple identifier separated by comma (,) or put this option
|
||||
|
||||
@@ -59,9 +59,12 @@ def get_argument_optional_choices(parser: ArgumentParser, argument_name: str) ->
|
||||
"""Get the optional_choices attribute of an argument from an ArgumentParser."""
|
||||
for action in parser._actions: # pylint: disable=protected-access
|
||||
opts = action.option_strings
|
||||
if (opts and opts[0] == argument_name) or action.dest == argument_name:
|
||||
if hasattr(action, "optional_choices"):
|
||||
return action.optional_choices
|
||||
if (
|
||||
(opts and opts[0] == argument_name)
|
||||
or action.dest == argument_name
|
||||
and hasattr(action, "optional_choices")
|
||||
):
|
||||
return action.optional_choices
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ from types import MethodType
|
||||
from typing import Dict, List, Optional
|
||||
|
||||
import pandas as pd
|
||||
from openbb import obb
|
||||
from openbb_charting.core.openbb_figure import OpenBBFigure
|
||||
from openbb_cli.argparse_translator.argparse_class_processor import (
|
||||
ArgparseClassProcessor,
|
||||
@@ -17,6 +16,8 @@ from openbb_cli.controllers.utils import export_data, print_rich_table
|
||||
from openbb_cli.session import Session
|
||||
from openbb_core.app.model.obbject import OBBject
|
||||
|
||||
from openbb import obb
|
||||
|
||||
session = Session()
|
||||
|
||||
|
||||
|
||||
@@ -274,6 +274,7 @@ def _get_argument_parser(
|
||||
" - parse_known_args_and_warn\n"
|
||||
)
|
||||
|
||||
# pylint: disable=possibly-used-before-assignment
|
||||
return argument_parser
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ from typing import Any, Dict, List, Optional
|
||||
|
||||
import pandas as pd
|
||||
import requests
|
||||
from openbb import obb
|
||||
from openbb_cli.config import constants
|
||||
from openbb_cli.config.constants import (
|
||||
ASSETS_DIRECTORY,
|
||||
@@ -48,6 +47,8 @@ from prompt_toolkit.formatted_text import HTML
|
||||
from prompt_toolkit.styles import Style
|
||||
from pydantic import BaseModel
|
||||
|
||||
from openbb import obb
|
||||
|
||||
PLATFORM_ROUTERS = {
|
||||
d: "menu" if not isinstance(getattr(obb, d), BaseModel) else "command"
|
||||
for d in dir(obb)
|
||||
@@ -291,7 +292,7 @@ class CLIController(BaseController):
|
||||
: session.settings.N_TO_DISPLAY_OBBJECT_REGISTRY
|
||||
]:
|
||||
mt.add_raw(
|
||||
f"[yellow]OBB{key}[/yellow]: {value['command']}",
|
||||
f"[yellow]OBB{key}[/yellow]: {value['command']}", # type: ignore[index]
|
||||
left_spacing=True,
|
||||
)
|
||||
|
||||
@@ -769,7 +770,6 @@ def replace_dynamic(match: re.Match, special_arguments: Dict[str, str]) -> str:
|
||||
str
|
||||
The new string
|
||||
"""
|
||||
|
||||
cleaned = match[0].replace("{", "").replace("}", "").replace("$", "")
|
||||
key, default = cleaned.split("=")
|
||||
dict_value = special_arguments.get(key, default)
|
||||
@@ -939,7 +939,6 @@ def launch(
|
||||
debug: bool = False, dev: bool = False, queue: Optional[List[str]] = None
|
||||
) -> None:
|
||||
"""Launch CLI."""
|
||||
|
||||
if queue:
|
||||
main(debug, dev, queue, module="")
|
||||
else:
|
||||
|
||||
@@ -16,7 +16,6 @@ from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import requests
|
||||
from openbb import obb
|
||||
from openbb_charting.core.backend import create_backend, get_backend
|
||||
from openbb_cli.config.constants import AVAILABLE_FLAIRS, ENV_FILE_SETTINGS
|
||||
from openbb_cli.session import Session
|
||||
@@ -24,6 +23,8 @@ from openbb_core.app.model.charts.charting_settings import ChartingSettings
|
||||
from pytz import all_timezones, timezone
|
||||
from rich.table import Table
|
||||
|
||||
from openbb import obb
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from openbb_charting.core.openbb_figure import OpenBBFigure
|
||||
|
||||
@@ -680,7 +681,6 @@ def remove_timezone_from_dataframe(df: pd.DataFrame) -> pd.DataFrame:
|
||||
pd.DataFrame
|
||||
The dataframe with timezone information removed
|
||||
"""
|
||||
|
||||
date_cols = []
|
||||
index_is_date = False
|
||||
|
||||
@@ -844,7 +844,6 @@ def export_data(
|
||||
margin : bool
|
||||
Automatically adjust subplot parameters to give specified padding.
|
||||
"""
|
||||
|
||||
if export_type:
|
||||
saved_path = compose_export_path(func_name, dir_path).resolve()
|
||||
saved_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@@ -4,11 +4,11 @@ import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from openbb import obb
|
||||
from openbb_core.app.model.abstract.singleton import SingletonMeta
|
||||
from openbb_core.app.model.user_settings import UserSettings as User
|
||||
from prompt_toolkit import PromptSession
|
||||
|
||||
from openbb import obb
|
||||
from openbb_cli.argparse_translator.obbject_registry import Registry
|
||||
from openbb_cli.config.completer import CustomFileHistory
|
||||
from openbb_cli.config.console import Console
|
||||
@@ -82,9 +82,6 @@ class Session(metaclass=SingletonMeta):
|
||||
"""Check if user is local."""
|
||||
return not bool(self.user.profile.hub_session)
|
||||
|
||||
def reset(self) -> None:
|
||||
pass
|
||||
|
||||
def max_obbjects_exceeded(self) -> bool:
|
||||
"""Check if max obbjects exceeded."""
|
||||
return (
|
||||
|
||||
@@ -14,7 +14,6 @@ from openbb_cli.controllers.utils import (
|
||||
print_goodbye,
|
||||
print_guest_block_msg,
|
||||
remove_file,
|
||||
reset,
|
||||
welcome_message,
|
||||
)
|
||||
|
||||
@@ -64,15 +63,6 @@ def test_print_goodbye(mock_session):
|
||||
mock_session.return_value.console.print.assert_called()
|
||||
|
||||
|
||||
def test_reset(mock_session):
|
||||
"""Test resetting the CLI."""
|
||||
with patch("openbb_cli.controllers.utils.remove_file"), patch(
|
||||
"sys.modules", new_callable=dict
|
||||
):
|
||||
reset()
|
||||
mock_session.return_value.console.print.assert_called()
|
||||
|
||||
|
||||
def test_parse_and_split_input():
|
||||
"""Test parsing and splitting user input."""
|
||||
user_input = "ls -f /home/user/docs/document.xlsx"
|
||||
|
||||
@@ -55,7 +55,10 @@ class QueryExecutor:
|
||||
if require_credentials:
|
||||
website = provider.website or ""
|
||||
extra_msg = f" Check {website} to get it." if website else ""
|
||||
raise OpenBBError(f"Missing credential '{c}'.{extra_msg}")
|
||||
raise OpenBBError(
|
||||
f"Missing credential '{c}'.{extra_msg} Known more about how to set provider "
|
||||
"credentials at https://docs.openbb.co/platform/getting_started/api_keys."
|
||||
)
|
||||
else:
|
||||
filtered_credentials[c] = secret
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ class Decorator:
|
||||
kwargs: Optional[dict] = None
|
||||
|
||||
|
||||
def get_decorator_details(function) -> Decorator:
|
||||
def get_decorator_details(function) -> Optional[Decorator]:
|
||||
"""Extract decorators and their arguments from a function."""
|
||||
source = inspect.getsource(function)
|
||||
parsed_source = parse(source)
|
||||
@@ -207,8 +207,8 @@ def get_decorator_details(function) -> Decorator:
|
||||
name = (
|
||||
decorator.id if isinstance(decorator, Name) else unparse(decorator)
|
||||
)
|
||||
|
||||
return Decorator(name, args, kwargs)
|
||||
return Decorator(name, args, kwargs)
|
||||
return None
|
||||
|
||||
|
||||
def find_missing_router_function_models(
|
||||
|
||||
@@ -34,6 +34,8 @@ def get_integration_tests(
|
||||
file_end = "_python.py"
|
||||
elif test_type == "api":
|
||||
file_end = "_api.py"
|
||||
else:
|
||||
raise ValueError(f"test_type '{test_type}' not valid")
|
||||
|
||||
for extension in find_extensions(filter_charting_ext):
|
||||
integration_folder = os.path.join(extension, "integration")
|
||||
|
||||
@@ -137,7 +137,7 @@ def check_router_command_examples() -> List[str]:
|
||||
)
|
||||
if decorator:
|
||||
decorator_details = get_decorator_details(function)
|
||||
if decorator_details.name == "router.command":
|
||||
if decorator_details and decorator_details.name == "router.command":
|
||||
keywords = decorator_details.kwargs or {}
|
||||
examples = keywords.get("examples", [])
|
||||
# General checks
|
||||
|
||||
@@ -1235,13 +1235,12 @@ def technical_relative_rotation(
|
||||
fig = relative_rotation.create_rrg_with_tails(
|
||||
ratios_df, momentum_df, study, benchmark_symbol, tail_periods, tail_interval # type: ignore
|
||||
)
|
||||
|
||||
if show_tails is False:
|
||||
else:
|
||||
fig = relative_rotation.create_rrg_without_tails(
|
||||
ratios_df, momentum_df, benchmark_symbol, study, date # type: ignore
|
||||
)
|
||||
|
||||
figure = OpenBBFigure(fig) # pylint: disable=E0606
|
||||
figure = OpenBBFigure(fig)
|
||||
font_color = "black" if ChartStyle().plt_style == "light" else "white"
|
||||
figure.update_layout(
|
||||
paper_bgcolor="rgba(0,0,0,0)",
|
||||
|
||||
@@ -203,6 +203,7 @@ def indicator(
|
||||
if not attrs.pop("name", ""):
|
||||
name = func.__name__
|
||||
|
||||
# pylint: disable=possibly-used-before-assignment
|
||||
return Indicator(func, name, **attrs)
|
||||
|
||||
return decorator
|
||||
|
||||
@@ -72,7 +72,6 @@ class ECBYieldCurveFetcher(
|
||||
**kwargs: Any,
|
||||
) -> List[Dict]:
|
||||
"""Extract data."""
|
||||
|
||||
results: List = []
|
||||
|
||||
IDS = get_yield_curve_ids(
|
||||
@@ -100,9 +99,9 @@ class ECBYieldCurveFetcher(
|
||||
await session.close()
|
||||
else:
|
||||
response = await amake_request(url=url)
|
||||
if not response: # pylint: disable=E0606
|
||||
if not response:
|
||||
raise RuntimeError("Error: No data was returned.")
|
||||
if isinstance(response, List): # pylint: disable=E0606
|
||||
if isinstance(response, List):
|
||||
for item in response:
|
||||
d = {
|
||||
"date": item.get("PERIOD"),
|
||||
|
||||
@@ -210,7 +210,7 @@ class FredRegionalDataFetcher(
|
||||
) -> Dict:
|
||||
"""Extract the raw data."""
|
||||
api_key = credentials.get("fred_api_key") if credentials else ""
|
||||
if query.is_series_group is True:
|
||||
if query.is_series_group:
|
||||
base_url = "https://api.stlouisfed.org/geofred/regional/data?"
|
||||
url = (
|
||||
base_url
|
||||
@@ -219,7 +219,7 @@ class FredRegionalDataFetcher(
|
||||
)
|
||||
+ f"&file_type=json&api_key={api_key}"
|
||||
)
|
||||
if query.is_series_group is False:
|
||||
else:
|
||||
base_url = "https://api.stlouisfed.org/geofred/series/data?"
|
||||
url = (
|
||||
base_url
|
||||
@@ -246,7 +246,6 @@ class FredRegionalDataFetcher(
|
||||
**kwargs,
|
||||
) -> List[FredRegionalData]:
|
||||
"""Flatten the response object and validate the model."""
|
||||
|
||||
results: List[FredRegionalData] = []
|
||||
if data.get("meta") is None:
|
||||
raise EmptyDataError()
|
||||
|
||||
@@ -251,13 +251,14 @@ class IntrinioCashFlowStatementFetcher(
|
||||
**kwargs: Any,
|
||||
) -> List[Dict]:
|
||||
"""Return the raw data from the Intrinio endpoint."""
|
||||
|
||||
api_key = credentials.get("intrinio_api_key") if credentials else ""
|
||||
statement_code = "cash_flow_statement"
|
||||
if query.period in ["quarter", "annual"]:
|
||||
period_type = "FY" if query.period == "annual" else "QTR"
|
||||
if query.period in ["ttm", "ytd"]:
|
||||
elif query.period in ["ttm", "ytd"]:
|
||||
period_type = query.period.upper()
|
||||
else:
|
||||
raise ValueError(f"Period '{query.period}' not supported.")
|
||||
|
||||
base_url = "https://api-v2.intrinio.com"
|
||||
fundamentals_url = (
|
||||
|
||||
@@ -153,13 +153,14 @@ class IntrinioFinancialRatiosFetcher(
|
||||
**kwargs: Any,
|
||||
) -> List[Dict]:
|
||||
"""Return the raw data from the Intrinio endpoint."""
|
||||
|
||||
api_key = credentials.get("intrinio_api_key") if credentials else ""
|
||||
statement_code = "calculations"
|
||||
if query.period in ["quarter", "annual"]:
|
||||
period_type = "FY" if query.period == "annual" else "QTR"
|
||||
if query.period in ["ttm", "ytd"]:
|
||||
elif query.period in ["ttm", "ytd"]:
|
||||
period_type = query.period.upper()
|
||||
else:
|
||||
raise ValueError(f"Period '{query.period}' not supported.")
|
||||
|
||||
fundamentals_data: Dict = {}
|
||||
|
||||
|
||||
@@ -402,8 +402,11 @@ class IntrinioIncomeStatementFetcher(
|
||||
statement_code = "income_statement"
|
||||
if query.period in ["quarter", "annual"]:
|
||||
period_type = "FY" if query.period == "annual" else "QTR"
|
||||
if query.period in ["ttm", "ytd"]:
|
||||
elif query.period in ["ttm", "ytd"]:
|
||||
period_type = query.period.upper()
|
||||
else:
|
||||
raise ValueError(f"Period '{query.period}' not supported.")
|
||||
|
||||
data_tags = [
|
||||
"ebit",
|
||||
"ebitda",
|
||||
|
||||
@@ -4,7 +4,7 @@ import ssl
|
||||
from datetime import date
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional, Union
|
||||
from typing import Any, Dict, Literal, Optional, Union
|
||||
|
||||
import requests
|
||||
import urllib3
|
||||
@@ -207,7 +207,7 @@ def get_possibly_cached_data(
|
||||
url: str,
|
||||
function: Optional[str] = None,
|
||||
query_dict: Optional[dict] = None,
|
||||
cache_method: str = "csv",
|
||||
cache_method: Literal["csv", "parquet"] = "csv",
|
||||
skip_cache: bool = False,
|
||||
) -> DataFrame:
|
||||
"""Retrieve data from a given URL or from the cache if available and valid.
|
||||
@@ -231,15 +231,11 @@ def get_possibly_cached_data(
|
||||
base_cache = (
|
||||
f"{cache}/{function}_{query_dict_to_path(query_dict if query_dict else {})}"
|
||||
)
|
||||
if cache_method == "parquet":
|
||||
cache_path = base_cache + ".parquet"
|
||||
elif cache_method == "csv":
|
||||
cache_path = base_cache + ".csv"
|
||||
|
||||
use_cache = check_cache_exists_and_valid(
|
||||
cache_str=base_cache, cache_method=cache_method
|
||||
)
|
||||
if use_cache and not skip_cache:
|
||||
cache_path = f"{base_cache}.{cache_method}"
|
||||
if cache_method == "csv":
|
||||
data = read_csv(cache_path)
|
||||
elif cache_method == "parquet":
|
||||
|
||||
@@ -571,7 +571,7 @@ async def download_eod_chains(
|
||||
|
||||
if date is None:
|
||||
EOD_URL = BASE_URL + f"{symbol}" "&dnld=1#quotes"
|
||||
if date is not None:
|
||||
else:
|
||||
date = check_weekday(date) # type: ignore
|
||||
if cal.is_session(date) is False: # type: ignore
|
||||
date = (pd.to_datetime(date) + timedelta(days=1)).strftime("%Y-%m-%d") # type: ignore
|
||||
|
||||
@@ -48,6 +48,7 @@ def generate_url(in_query):
|
||||
# Construct URL based on query parameters
|
||||
# Country Only
|
||||
if check_args(query, ["country"]):
|
||||
# pylint: disable=possibly-used-before-assignment
|
||||
url = f"{base_url}/country/{country}?c="
|
||||
# Country + Date
|
||||
elif check_args(query, ["country", "start_date", "end_date"]):
|
||||
@@ -59,6 +60,7 @@ def generate_url(in_query):
|
||||
url = f"{base_url}/country/{country}?{urlencode(query)}&c="
|
||||
# Country + Group
|
||||
elif check_args(query, ["country", "group"]):
|
||||
# pylint: disable=possibly-used-before-assignment
|
||||
url = f"{base_url}/country/{country}/group/{group}?c="
|
||||
# Country + Group + Date
|
||||
elif check_args(query, ["country", "group", "start_date", "end_date"]):
|
||||
|
||||
@@ -70,6 +70,7 @@ class YFinanceCompanyNewsFetcher(
|
||||
async def get_one(symbol):
|
||||
data = Ticker(symbol).get_news()
|
||||
for d in data:
|
||||
images = None
|
||||
if d.get("thumbnail"):
|
||||
images = d["thumbnail"].get("resolutions")
|
||||
_ = d.pop("uuid")
|
||||
|
||||
@@ -81,14 +81,12 @@ class YFinanceCryptoHistoricalFetcher(
|
||||
**kwargs: Any,
|
||||
) -> List[Dict]:
|
||||
"""Return the raw data from the Yahoo Finance endpoint."""
|
||||
|
||||
tickers = query.symbol.split(",")
|
||||
new_tickers = []
|
||||
for ticker in tickers:
|
||||
if "-" not in ticker:
|
||||
new_ticker = ticker[:-3] + "-" + ticker[-3:]
|
||||
if "-" in ticker:
|
||||
new_ticker = ticker
|
||||
new_ticker = (
|
||||
ticker[:-3] + "-" + ticker[-3:] if "-" not in ticker else ticker
|
||||
)
|
||||
new_tickers.append(new_ticker)
|
||||
|
||||
symbols = ",".join(new_tickers)
|
||||
|
||||
@@ -85,11 +85,9 @@ class YFinanceFuturesHistoricalFetcher(
|
||||
exchange = futures_data[futures_data["Ticker"] == symbol][
|
||||
"Exchange"
|
||||
].values[0]
|
||||
new_symbol = (
|
||||
f"{symbol}{MONTHS[expiry_date.month]}{str(expiry_date.year)[-2:]}.{exchange}"
|
||||
if "." not in symbol
|
||||
else symbol
|
||||
)
|
||||
new_symbol = f"{symbol}{MONTHS[expiry_date.month]}{str(expiry_date.year)[-2:]}.{exchange}"
|
||||
else:
|
||||
new_symbol = symbol
|
||||
new_symbols.append(new_symbol)
|
||||
else:
|
||||
new_symbols.append(symbol)
|
||||
|
||||
Reference in New Issue
Block a user