Skip to content

Commit 7dc591a

Browse files
committed
🐛 mypy linting
1 parent 7dfd227 commit 7dc591a

File tree

10 files changed

+79
-67
lines changed

10 files changed

+79
-67
lines changed

lunchable/_cli.py

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import logging
66
from json import JSONDecodeError
7-
from typing import Optional
7+
from typing import Any, Dict, Optional, Union
88

99
import click
1010
import requests
@@ -58,14 +58,14 @@ def cli(ctx: click.core.Context, debug: bool, access_token: str) -> None:
5858

5959

6060
@cli.group()
61-
def transactions():
61+
def transactions() -> None:
6262
"""
6363
Interact with Lunch Money transactions
6464
"""
6565

6666

6767
@cli.group()
68-
def plugins():
68+
def plugins() -> None:
6969
"""
7070
Interact with Lunchable Plugins
7171
"""
@@ -133,17 +133,19 @@ def plugins():
133133
help="Pass in true if you’d like to include imported transactions with a pending status.",
134134
)
135135
@click.pass_obj
136-
def lunchmoney_transactions(context: LunchMoneyContext, **kwargs):
136+
def lunchmoney_transactions(
137+
context: LunchMoneyContext, **kwargs: Dict[str, Any]
138+
) -> None:
137139
"""
138140
Retrieve Lunch Money Transactions
139141
"""
140142
lunch = LunchMoney(access_token=context.access_token)
141-
transactions = lunch.get_transactions(**kwargs)
143+
transactions = lunch.get_transactions(**kwargs) # type: ignore[arg-type]
142144
print_json(data=transactions, default=pydantic_encoder)
143145

144146

145147
@plugins.group()
146-
def splitlunch():
148+
def splitlunch() -> None:
147149
"""
148150
Splitwise Plugin for lunchable, SplitLunch 💲🍱
149151
"""
@@ -178,7 +180,7 @@ def splitlunch():
178180
default=None,
179181
help="ISO 8601 Date time. Return expenses updated before this date",
180182
)
181-
def splitlunch_expenses(**kwargs):
183+
def splitlunch_expenses(**kwargs: Union[int, str, bool]) -> None:
182184
"""
183185
Retrieve Splitwise Expenses
184186
"""
@@ -187,7 +189,7 @@ def splitlunch_expenses(**kwargs):
187189
splitlunch = SplitLunch()
188190
if set(kwargs.values()) == {None}:
189191
kwargs["limit"] = 5
190-
expenses = splitlunch.get_expenses(**kwargs)
192+
expenses = splitlunch.get_expenses(**kwargs) # type: ignore[arg-type]
191193
print_json(data=expenses, default=pydantic_encoder)
192194

193195

@@ -217,7 +219,7 @@ def splitlunch_expenses(**kwargs):
217219

218220
@splitlunch.command("splitlunch")
219221
@tag_transactions
220-
def make_splitlunch(**kwargs):
222+
def make_splitlunch(**kwargs: Union[int, str, bool]) -> None:
221223
"""
222224
Split all `SplitLunch` tagged transactions in half.
223225
@@ -226,7 +228,7 @@ def make_splitlunch(**kwargs):
226228
from lunchable.plugins.splitlunch import SplitLunch
227229

228230
splitlunch = SplitLunch()
229-
results = splitlunch.make_splitlunch(**kwargs)
231+
results = splitlunch.make_splitlunch(**kwargs) # type: ignore[arg-type]
230232
print_json(data=results, default=pydantic_encoder)
231233

232234

@@ -235,7 +237,7 @@ def make_splitlunch(**kwargs):
235237
@financial_partner_id
236238
@financial_partner_email
237239
@financial_partner_group_id
238-
def make_splitlunch_import(**kwargs):
240+
def make_splitlunch_import(**kwargs: Union[int, str, bool]) -> None:
239241
"""
240242
Import `SplitLunchImport` tagged transactions to Splitwise and Split them in Lunch Money
241243
@@ -245,15 +247,21 @@ def make_splitlunch_import(**kwargs):
245247
"""
246248
from lunchable.plugins.splitlunch import SplitLunch
247249

248-
financial_partner_id = kwargs.pop("financial_partner_id")
249-
financial_partner_email = kwargs.pop("financial_partner_email")
250-
financial_partner_group_id = kwargs.pop("financial_partner_group_id")
250+
financial_partner_id: Optional[int] = kwargs.pop(
251+
"financial_partner_id"
252+
) # type: ignore[assignment]
253+
financial_partner_email: Optional[str] = kwargs.pop(
254+
"financial_partner_email"
255+
) # type: ignore[assignment]
256+
financial_partner_group_id: Optional[int] = kwargs.pop(
257+
"financial_partner_group_id"
258+
) # type: ignore[assignment]
251259
splitlunch = SplitLunch(
252260
financial_partner_id=financial_partner_id,
253261
financial_partner_email=financial_partner_email,
254262
financial_partner_group_id=financial_partner_group_id,
255263
)
256-
results = splitlunch.make_splitlunch_import(**kwargs)
264+
results = splitlunch.make_splitlunch_import(**kwargs) # type: ignore[arg-type]
257265
print_json(data=results, default=pydantic_encoder)
258266

259267

@@ -262,7 +270,7 @@ def make_splitlunch_import(**kwargs):
262270
@financial_partner_id
263271
@financial_partner_email
264272
@financial_partner_group_id
265-
def make_splitlunch_direct_import(**kwargs):
273+
def make_splitlunch_direct_import(**kwargs: Union[int, str, bool]) -> None:
266274
"""
267275
Import `SplitLunchDirectImport` tagged transactions to Splitwise and Split them in Lunch Money
268276
@@ -272,20 +280,26 @@ def make_splitlunch_direct_import(**kwargs):
272280
"""
273281
from lunchable.plugins.splitlunch import SplitLunch
274282

275-
financial_partner_id = kwargs.pop("financial_partner_id")
276-
financial_partner_email = kwargs.pop("financial_partner_email")
277-
financial_partner_group_id = kwargs.pop("financial_partner_group_id")
283+
financial_partner_id: Optional[int] = kwargs.pop(
284+
"financial_partner_id"
285+
) # type: ignore[assignment]
286+
financial_partner_email: Optional[str] = kwargs.pop(
287+
"financial_partner_email"
288+
) # type: ignore[assignment]
289+
financial_partner_group_id: Optional[int] = kwargs.pop(
290+
"financial_partner_group_id"
291+
) # type: ignore[assignment]
278292
splitlunch = SplitLunch(
279293
financial_partner_id=financial_partner_id,
280294
financial_partner_email=financial_partner_email,
281295
financial_partner_group_id=financial_partner_group_id,
282296
)
283-
results = splitlunch.make_splitlunch_direct_import(**kwargs)
297+
results = splitlunch.make_splitlunch_direct_import(**kwargs) # type: ignore[arg-type]
284298
print_json(data=results, default=pydantic_encoder)
285299

286300

287301
@splitlunch.command("update-balance")
288-
def update_splitwise_balance(**kwargs):
302+
def update_splitwise_balance() -> None:
289303
"""
290304
Update the Splitwise Asset Balance
291305
"""
@@ -297,7 +311,7 @@ def update_splitwise_balance(**kwargs):
297311

298312

299313
@splitlunch.command("refresh")
300-
def refresh_splitwise_transactions(**kwargs):
314+
def refresh_splitwise_transactions() -> None:
301315
"""
302316
Import New Splitwise Transactions to Lunch Money and
303317
@@ -313,7 +327,7 @@ def refresh_splitwise_transactions(**kwargs):
313327

314328

315329
@plugins.group()
316-
def pushlunch():
330+
def pushlunch() -> None:
317331
"""
318332
Push Notifications for Lunch Money: PushLunch 📲
319333
"""
@@ -338,7 +352,7 @@ def pushlunch():
338352
default=None,
339353
help="Pushover User Key. Defaults to `PUSHOVER_USER_KEY` env var",
340354
)
341-
def notify(continuous: bool, interval: int, user_key: str):
355+
def notify(continuous: bool, interval: int, user_key: str) -> None:
342356
"""
343357
Send a Notification for each Uncleared Transaction
344358
"""
@@ -355,7 +369,7 @@ def notify(continuous: bool, interval: int, user_key: str):
355369
@click.option("-X", "--request", default="GET", help="Specify request command to use")
356370
@click.option("-d", "--data", default=None, help="HTTP POST data")
357371
@click.pass_obj
358-
def http(context: LunchMoneyContext, url: str, request: str, data: str):
372+
def http(context: LunchMoneyContext, url: str, request: str, data: str) -> None:
359373
"""
360374
Interact with the LunchMoney API
361375
@@ -386,7 +400,7 @@ def http(context: LunchMoneyContext, url: str, request: str, data: str):
386400

387401

388402
@plugins.group()
389-
def primelunch():
403+
def primelunch() -> None:
390404
"""
391405
PrimeLunch CLI - Syncing LunchMoney with Amazon
392406
"""

lunchable/_config/api_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def get_header(access_token: Optional[str] = None) -> Dict[str, str]:
8686
return auth_header
8787

8888
@staticmethod
89-
def make_url(url_path: Union[List[Union[str, int]], str, int]):
89+
def make_url(url_path: Union[List[Union[str, int]], str, int]) -> str:
9090
"""
9191
Make a Lunch Money API URL using path parts
9292
@@ -126,7 +126,7 @@ def _generate_url(
126126
params: str = "",
127127
query: str = "",
128128
fragment: str = "",
129-
):
129+
) -> str:
130130
"""
131131
Build a URL
132132

lunchable/models/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class LunchableModel(BaseModel):
1010
Hashable Pydantic Model
1111
"""
1212

13-
def __hash__(self):
13+
def __hash__(self) -> int:
1414
"""
1515
Hash Method for Pydantic BaseModels
1616
"""

lunchable/models/_core.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import json
77
import logging
88
from json import loads
9-
from typing import Any, List, Optional, Union
9+
from typing import Any, Dict, List, Optional, Union
1010

1111
import requests
1212

@@ -76,7 +76,7 @@ def __repr__(self) -> str:
7676
return "<LunchMoney: requests.Session>"
7777

7878
@staticmethod
79-
def _serializer(obj):
79+
def _serializer(obj: Any) -> str:
8080
if isinstance(obj, datetime.datetime):
8181
return obj.isoformat()
8282
elif isinstance(obj, datetime.date):
@@ -88,9 +88,9 @@ def _make_request(
8888
self,
8989
method: str,
9090
url_path: Union[List[Union[str, int]], str, int],
91-
params: Optional[dict] = None,
91+
params: Optional[Dict[str, Any]] = None,
9292
payload: Optional[Any] = None,
93-
**kwargs
93+
**kwargs: Any
9494
) -> Any:
9595
"""
9696
Make a Request to the API
@@ -102,7 +102,7 @@ def _make_request(
102102
PATCH, or DELETE
103103
url_path: Union[List[Union[str, int]], str, int]
104104
API Components, if a list join these sequentially
105-
params: Optional[dict]
105+
params: Optional[Dict[str, Any]]
106106
Params to pass
107107
payload: Optional[Any]
108108
data to pass
@@ -143,7 +143,7 @@ def make_http_request(
143143
params: Optional[Any] = None,
144144
data: Optional[Any] = None,
145145
json: Optional[Any] = None,
146-
**kwargs
146+
**kwargs: Any
147147
) -> requests.Response:
148148
"""
149149
Make a HTTP Request

lunchable/models/assets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import datetime
88
import logging
9-
from typing import List, Optional
9+
from typing import List, Optional, Union
1010

1111
from pydantic import Field, validator
1212

@@ -87,7 +87,7 @@ class _AssetsParamsPut(LunchableModel):
8787

8888
@classmethod
8989
@validator("balance", pre=True)
90-
def result_check(cls, x):
90+
def result_check(cls, x: Union[float, int]) -> float:
9191
"""
9292
Check a result
9393
"""
@@ -112,7 +112,7 @@ class _AssetsParamsPost(LunchableModel):
112112

113113
@classmethod
114114
@validator("balance", pre=True)
115-
def result_check(cls, x):
115+
def result_check(cls, x: Union[float, int]) -> float:
116116
"""
117117
Check a result
118118
"""

lunchable/models/transactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def get_transactions(
446446
limit: Optional[int] = None,
447447
debit_as_negative: Optional[bool] = None,
448448
pending: Optional[bool] = None,
449-
params: Optional[dict] = None,
449+
params: Optional[Dict[str, Any]] = None,
450450
) -> List[TransactionObject]:
451451
"""
452452
Get Transactions Using Criteria

lunchable/plugins/base/base_app.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class LunchableDataModel(LunchableModel):
3838
"""
3939

4040
model: Type[LunchableModel]
41-
function: Callable
41+
function: Callable[[Any], Any]
4242
kwargs: Dict[str, Any] = {}
4343

4444

@@ -77,7 +77,7 @@ class BaseLunchableApp(ABC):
7777
Abstract Base Class for Lunchable Apps
7878
"""
7979

80-
__lunchable_object_mapping__: dict[str, str] = {
80+
__lunchable_object_mapping__: Dict[str, str] = {
8181
PlaidAccountObject.__name__: "plaid_accounts",
8282
TransactionObject.__name__: "transactions",
8383
CategoriesObject.__name__: "categories",
@@ -133,7 +133,7 @@ def __init__(self, cache_time: int = 0, access_token: Optional[str] = None):
133133
def _cache_single_object(
134134
self,
135135
model: Type[LunchableModelType],
136-
function: Callable,
136+
function: Callable[[Any], Any],
137137
kwargs: Optional[Dict[str, Any]] = None,
138138
force: bool = False,
139139
) -> Union[LunchableModelType, List[LunchableModelType]]:
@@ -144,7 +144,7 @@ def _cache_single_object(
144144
----------
145145
model: Type[LunchableModel]
146146
function: Callable
147-
kwargs: dict[str, Any]
147+
kwargs: Optional[Dict[str, Any]]
148148
force: bool
149149
150150
Returns
@@ -166,7 +166,7 @@ def _cache_single_object(
166166
else:
167167
refresh = True
168168
if refresh is True:
169-
data_objects = function(**kwargs)
169+
data_objects = function(**kwargs) # type: ignore[call-arg]
170170
if self.cache_time > 0:
171171
plain_data: str = json.dumps(data_objects, default=pydantic_encoder)
172172
base64_data: bytes = base64.b64encode(plain_data.encode("utf-8"))
@@ -224,7 +224,7 @@ def get_latest_cache(
224224
)
225225
cache_attribute: Union[Dict[int, LunchableModel], LunchableModel]
226226
if isinstance(cache, list):
227-
cache_attribute = {item.id: item for item in cache} # type: ignore
227+
cache_attribute = {item.id: item for item in cache}
228228
else:
229229
cache_attribute = cache
230230
setattr(

0 commit comments

Comments
 (0)