Changeset - ed0bc469ce5a
[Not reviewed]
0 2 0
Ben Sturmfels (bsturmfels) - 2 years ago 2022-02-04 08:15:11
ben@sturm.com.au
reconcile: Add type checking information to new prototype reconcilers.
2 files changed with 17 insertions and 13 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reconcile/helper.py
Show inline comments
...
 
@@ -22,2 +22,4 @@ import tempfile
 
import textwrap
 
import typing
 
from typing import List
 
import os
...
 
@@ -28,3 +30,3 @@ from beancount.query.query import run_query
 

	
 
def end_of_month(date):
 
def end_of_month(date: datetime.date) -> datetime.date:
 
    """Given a date, return the last day of the month."""
...
 
@@ -34,3 +36,3 @@ def end_of_month(date):
 

	
 
def format_record_for_grep(row, homedir):
 
def format_record_for_grep(row: typing.List, homedir: str) -> typing.List:
 
    """Return a line in a grep-style.
...
 
@@ -44,3 +46,3 @@ def format_record_for_grep(row, homedir):
 

	
 
def max_column_widths(rows):
 
def max_column_widths(rows: List) -> List[int]:
 
    """Return the max width for each column in a table of data."""
...
 
@@ -57,3 +59,3 @@ def max_column_widths(rows):
 

	
 
def tabulate(rows, headers=None):
 
def tabulate(rows: List, headers: List=None) -> str:
 
    """Format a table of data as a string.
...
 
@@ -103,4 +105,5 @@ else:
 
    preDate = args.prev_end_date
 
    lastDateInPeriod = args.cur_end_date
 
    month = lastDateInPeriod.strftime('%Y-%m')
 
    lastDateInPeriod = args.cur_end_date.isoformat()
 
    month = args.cur_end_date.strftime('%Y-%m')
 
grep_output_file: typing.IO
 
if args.grep_output_filename:
...
 
@@ -170,3 +173,3 @@ for desc, query in QUERIES.items():
 
    elif desc.startswith('04'):
 
        homedir = os.getenv('HOME')
 
        homedir = os.getenv('HOME', '')
 
        print(f'{desc}\n   See {grep_output_file.name}')
conservancy_beancount/reconcile/prototype_amex_reconciler.py
Show inline comments
...
 
@@ -12,2 +12,3 @@ import datetime
 
import decimal
 
from typing import Dict, List, Tuple
 

	
...
 
@@ -15,3 +16,3 @@ from beancount import loader
 
from beancount.query.query import run_query
 
from thefuzz import fuzz
 
from thefuzz import fuzz  # type: ignore
 

	
...
 
@@ -19,3 +20,3 @@ from thefuzz import fuzz
 

	
 
def standardize_amex_record(row):
 
def standardize_amex_record(row: Dict) -> Dict:
 
    return {
...
 
@@ -27,3 +28,3 @@ def standardize_amex_record(row):
 

	
 
def standardize_beancount_record(row):
 
def standardize_beancount_record(row) -> Dict:  # type: ignore[no-untyped-def]
 
    return {
...
 
@@ -35,3 +36,3 @@ def standardize_beancount_record(row):
 

	
 
def format_record(record):
 
def format_record(record: Dict) -> str:
 
    return f"{record['date'].isoformat()}: {record['amount']:>8} {record['payee'][:20]:<20}"
...
 
@@ -39,3 +40,3 @@ def format_record(record):
 

	
 
def sort_records(records):
 
def sort_records(records: List) -> List:
 
    return sorted(records, key=lambda x: (x['date'], x['amount']))
...
 
@@ -43,3 +44,3 @@ def sort_records(records):
 

	
 
def records_match(r1, r2):
 
def records_match(r1: Dict, r2: Dict) -> Tuple[bool, str]:
 
    """Do these records represent the same transaction?"""
0 comments (0 inline, 0 general)