Skip to content

Commit

Permalink
fix new warnings/errors after mypy upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
cdump committed Mar 25, 2023
1 parent be23972 commit 24fcbc4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion investments/data_providers/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get(self) -> Optional[pandas.DataFrame]:

if (datetime.datetime.utcnow() - datetime.datetime.utcfromtimestamp(mtime)) > self._ttl:
return None
return pandas.read_pickle(self._cache_file)
return pandas.read_pickle(self._cache_file) # noqa:S301

def put(self, df: pandas.DataFrame):
if self._cache_file is not None:
Expand Down
4 changes: 2 additions & 2 deletions investments/data_providers/cbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ExchangeRatesRUB:
_cache_dir: Optional[str]
_frames_loaded: Dict[str, pandas.DataFrame]

def __init__(self, year_from: int = 2000, cache_dir: str = None):
def __init__(self, year_from: int = 2000, cache_dir: Optional[str] = None):
self._year_from = year_from
self._cache_dir = cache_dir
self._frames_loaded = {}
Expand Down Expand Up @@ -63,7 +63,7 @@ def _fetch_currency_rates(self, currency: Currency):
return

end_date = (datetime.datetime.utcnow() + datetime.timedelta(days=1)).strftime('%d/%m/%Y')
r = requests.get(f'http://www.cbr.ru/scripts/XML_dynamic.asp?date_req1=01/01/{self._year_from}&date_req2={end_date}&VAL_NM_RQ={currency.cbr_code}')
r = requests.get(f'http://www.cbr.ru/scripts/XML_dynamic.asp?date_req1=01/01/{self._year_from}&date_req2={end_date}&VAL_NM_RQ={currency.cbr_code}', timeout=10)

tree = ET.fromstring(r.text)

Expand Down
2 changes: 1 addition & 1 deletion investments/data_providers/moex.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ async def async_get_board_candles(ticker: Ticker, cache_dir: Optional[str], star
return df


def get_board_candles(ticker: Ticker, cache_dir: str = None, start='2016-01-01', end=None, interval=24):
def get_board_candles(ticker: Ticker, cache_dir: Optional[str] = None, start='2016-01-01', end=None, interval=24):
return asyncio.run(async_get_board_candles(ticker, cache_dir, start, end, interval))
6 changes: 3 additions & 3 deletions investments/ibtax/ibtax.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def parse_reports(activity_reports_dir: str, confirmation_reports_dir: str) -> I
return parser_object


def main():
sys.stdout.reconfigure(encoding='utf-8')
def main() -> None:
sys.stdout.reconfigure(encoding='utf-8') # type: ignore

available_report_types: Dict[str, Type[ReportPresenter]] = {
'native': NativeReportPresenter,
Expand Down Expand Up @@ -203,7 +203,7 @@ def main():

trades_report = prepare_trades_report(finished_trades, cbr_client_usd) if finished_trades else None

presenter = available_report_types.get(args.report_type)(args.verbose, args.save_to)
presenter = available_report_types[args.report_type](args.verbose, args.save_to)
presenter.prepare_report(trades_report, dividends_report, fees_report, interests_report, portfolio, args.years)
presenter.present()

Expand Down
14 changes: 7 additions & 7 deletions investments/report_parsers/ib.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def parse_header(self, fields: List[str]):
def parse(self, row: List[str]) -> Dict[str, str]:
error_msg = f'expect {len(self._fields)} rows {self._fields}, but got {len(row)} rows ({row})'
assert len(row) == len(self._fields), error_msg
return {k: v for k, v in zip(self._fields, row)}
return dict(zip(self._fields, row))


class TickersStorage:
Expand Down Expand Up @@ -107,7 +107,7 @@ class SettleDate(NamedTuple):


class SettleDatesStorage:
def __init__(self):
def __init__(self) -> None:
self._settle_data: Dict[Tuple[str, datetime.datetime], SettleDate] = {}

def __len__(self):
Expand Down Expand Up @@ -145,13 +145,13 @@ def get_date(


class InteractiveBrokersReportParser:
def __init__(self):
self._trades = []
self._dividends = []
def __init__(self) -> None:
self._trades: List[Trade] = []
self._dividends: List[Dividend] = []
self._fees: List[Fee] = []
self._interests: List[Interest] = []
self._cash: List[Cash] = []
self._deposits_and_withdrawals = []
self._deposits_and_withdrawals: List[Tuple[datetime.date, Money]] = []
self._tickers = TickersStorage()
self._settle_dates = SettleDatesStorage()

Expand All @@ -167,7 +167,7 @@ def dividends(self) -> List[Dividend]:
return self._dividends

@property
def deposits_and_withdrawals(self) -> List:
def deposits_and_withdrawals(self) -> List[Tuple[datetime.date, Money]]:
return self._deposits_and_withdrawals

@property
Expand Down
3 changes: 1 addition & 2 deletions tests/trades_fifo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_analyze_trades_without_fees(trades, expect_trades):
assert expected[2] == trade.quantity, f'expect trade quantity={expected[2]} but got {trade.quantity}'


def test_trades_fees_simple():
def test_trades_fees_simple() -> None:
request_trades = []
ticker = Ticker(symbol='VT', kind=TickerKind.Stock)

Expand Down Expand Up @@ -131,4 +131,3 @@ def test_trades_precision() -> List[FinishedTrade]:
assert sell_trade.fee_per_piece.amount == Decimal('-0.101812674')

return finished_trades

0 comments on commit 24fcbc4

Please sign in to comment.