From c78eea6dbacee7ed066b7448f52fe49002eece81 Mon Sep 17 00:00:00 2001 From: Santiago Fraire Date: Sat, 30 Mar 2024 18:01:48 +0100 Subject: [PATCH] fix: linting and types --- pyproject.toml | 3 +++ src/ficamp/classifier/features.py | 3 ++- src/ficamp/parsers/abn.py | 1 + src/ficamp/parsers/banc_sabadell.py | 21 +++++++++++---------- src/ficamp/parsers/bbva.py | 3 ++- tests/test_google_api.py | 1 + tests/test_parsers_abn.py | 1 + 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 513c05e..f3902b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,3 +34,6 @@ ignore_missing_imports = true [tool.ruff.lint] select = ["I"] + +[tool.ruff.lint.isort] +known-first-party = ["ficamp", "tests"] diff --git a/src/ficamp/classifier/features.py b/src/ficamp/classifier/features.py index b75ab3a..d285aad 100644 --- a/src/ficamp/classifier/features.py +++ b/src/ficamp/classifier/features.py @@ -1,5 +1,6 @@ from dataclasses import dataclass from functools import lru_cache +from typing import Any import numpy as np from sklearn.utils import murmurhash3_32 @@ -46,7 +47,7 @@ def extract_city(d) -> str: return d | {"city": "Lleida"} -def extract_payment_method(d: dict) -> str: +def extract_payment_method(d: dict) -> str | dict[str, Any]: "Return payment method name in lowercase if found, else " # TODO:improve logic diff --git a/src/ficamp/parsers/abn.py b/src/ficamp/parsers/abn.py index aa527a7..bba7e56 100644 --- a/src/ficamp/parsers/abn.py +++ b/src/ficamp/parsers/abn.py @@ -9,6 +9,7 @@ from pathlib import Path import xlrd # type: ignore + from ficamp.datastructures import Currency, Tx from ficamp.parsers.protocols import Parser diff --git a/src/ficamp/parsers/banc_sabadell.py b/src/ficamp/parsers/banc_sabadell.py index f49904d..38aa217 100644 --- a/src/ficamp/parsers/banc_sabadell.py +++ b/src/ficamp/parsers/banc_sabadell.py @@ -3,10 +3,11 @@ from decimal import Decimal from pathlib import Path -from ficamp.parsers.protocol import Parser -from ficamp.types import Tx from openpyxl import load_workbook +from ficamp.datastructures import Tx +from ficamp.parsers.protocols import Parser + class AccountBSabadellParser(Parser): """Parser for BBVA bank account extract""" @@ -15,10 +16,10 @@ def load(self, filename: Path | None = None): # TODO: rearrange this. # filename = Path("../data/enero-febrero-bbva-cuenta.xlsx") - filename = os.path.join( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))), - "data/enero-febrero-bsabadell-cuenta.xlsx", - ) + # filename = os.path.join( + # os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + # "data/enero-febrero-bsabadell-cuenta.xlsx", + # ) wb = load_workbook(filename) sheet = wb.active @@ -80,10 +81,10 @@ class CreditCardBSabadellParser(Parser): def load(self, filename: Path | None = None): # TODO: rearrange this # filename = Path("../data/enero-febrero-bbva-cuenta.xlsx") - filename = os.path.join( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))), - "data/enero-febrero-bsabadell-targeta.xlsx", - ) + # filename = os.path.join( + # os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + # "data/enero-febrero-bsabadell-targeta.xlsx", + # ) wb = load_workbook(filename) sheet = wb.active diff --git a/src/ficamp/parsers/bbva.py b/src/ficamp/parsers/bbva.py index 527816d..47179c9 100644 --- a/src/ficamp/parsers/bbva.py +++ b/src/ficamp/parsers/bbva.py @@ -2,9 +2,10 @@ from decimal import Decimal from pathlib import Path +from openpyxl import load_workbook + from ficamp.datastructures import Tx from ficamp.parsers.protocols import Parser -from openpyxl import load_workbook class AccountBBVAParser(Parser): diff --git a/tests/test_google_api.py b/tests/test_google_api.py index 625d166..66146af 100644 --- a/tests/test_google_api.py +++ b/tests/test_google_api.py @@ -1,5 +1,6 @@ import pytest import requests_mock + from ficamp.classifier.google_apis import ( GoogleException, find_business_category_in_google, diff --git a/tests/test_parsers_abn.py b/tests/test_parsers_abn.py index 498da8a..1dc4e18 100644 --- a/tests/test_parsers_abn.py +++ b/tests/test_parsers_abn.py @@ -2,6 +2,7 @@ from decimal import Decimal import pytest + from ficamp.parsers.abn import ( ConceptParser, amount_parser,