From 7c9f39ec0c62057cd959f5bb328a3743a280745e Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 6 Mar 2021 12:38:17 +0100 Subject: [PATCH] GitHub Actions: Make mypy a mandatory test --- .github/workflows/test.yml | 2 +- gamestonk_terminal/helper_funcs.py | 25 +++++++++------------ gamestonk_terminal/sentiment/twitter_api.py | 2 +- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07938ca8c8a..dd32b278ce5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,7 @@ jobs: - run: black --check . - run: codespell --ignore-words-list="mape" --quiet-level=2 --skip=".git" # --skip="" - run: flake8 . --count --ignore=E203,E302,F401,F841,W503 --max-line-length=140 --show-source --statistics - - run: mypy --ignore-missing-imports . || true + - run: mypy --ignore-missing-imports . - run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true - run: safety check - run: pylint **/*.py diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index 7f9f21b0759..0c25390f896 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -161,34 +161,29 @@ def long_number_format(num) -> str: def clean_data_values_to_float(val: str) -> float: - # Remove parenthesis if they exist - if val.startswith("("): - val = val[1:] - if val.endswith(")"): - val = val[:-1] - + # Remove any leading or trailing parentheses and spaces + val = val.strip("( )") if val == "-": val = "0" # Convert percentage to decimal if val.endswith("%"): - val = float(val[:-1]) / 100.0 + val_as_float = float(val[:-1]) / 100.0 # Convert from billions elif val.endswith("B"): - val = float(val[:-1]) * 1_000_000_000 + val_as_float = float(val[:-1]) * 1_000_000_000 # Convert from millions elif val.endswith("M"): - val = float(val[:-1]) * 1_000_000 + val_as_float = float(val[:-1]) * 1_000_000 # Convert from thousands elif val.endswith("K"): - val = float(val[:-1]) * 1000 + val_as_float = float(val[:-1]) * 1000 else: - val = float(val) - - return val + val_as_float = float(val) + return val_as_float -def int_or_round_float(x): +def int_or_round_float(x) -> str: if (x - int(x) < -sys.float_info.epsilon) or (x - int(x) > sys.float_info.epsilon): return " " + str(round(x, 2)) @@ -221,7 +216,7 @@ def get_next_stock_market_days(last_stock_day, n_next_days) -> list: return l_pred_days -def get_data(tweet) -> hash: +def get_data(tweet): if "+" in tweet["created_at"]: s_datetime = tweet["created_at"].split(" +")[0] else: diff --git a/gamestonk_terminal/sentiment/twitter_api.py b/gamestonk_terminal/sentiment/twitter_api.py index 31579279f3f..4e52eae007f 100644 --- a/gamestonk_terminal/sentiment/twitter_api.py +++ b/gamestonk_terminal/sentiment/twitter_api.py @@ -23,7 +23,7 @@ def load_tweets(s_ticker: str, count: int) -> DataFrame: # Request Twitter API response = requests.get( "https://api.twitter.com/1.1/search/tweets.json", - params=params, + params=params, # type: ignore headers={"authorization": "Bearer " + cfg.API_TWITTER_BEARER_TOKEN}, )