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
...
 
@@ -21,4 +21,6 @@ import io
 
import tempfile
 
import textwrap
 
import typing
 
from typing import List
 
import os
 

	
...
 
@@ -27,5 +29,5 @@ 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."""
 
    # Using 'day' replaces, rather than adds.
...
 
@@ -33,5 +35,5 @@ 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.
 

	
...
 
@@ -43,5 +45,5 @@ 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."""
 
    if not rows:
...
 
@@ -56,5 +58,5 @@ 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.
 

	
...
 
@@ -102,6 +104,7 @@ else:
 
        parser.error(' --prev-end-date and --cur-end-date must be used together')
 
    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:
 
    grep_output_file = open(args.grep_output_filename, 'w')
...
 
@@ -169,5 +172,5 @@ for desc, query in QUERIES.items():
 
        print(f'{desc:<55} {"N/A":>11}')
 
    elif desc.startswith('04'):
 
        homedir = os.getenv('HOME')
 
        homedir = os.getenv('HOME', '')
 
        print(f'{desc}\n   See {grep_output_file.name}')
 
        grep_rows = [format_record_for_grep(row, homedir) for row in rrows]
conservancy_beancount/reconcile/prototype_amex_reconciler.py
Show inline comments
...
 
@@ -11,12 +11,13 @@ import csv
 
import datetime
 
import decimal
 
from typing import Dict, List, Tuple
 

	
 
from beancount import loader
 
from beancount.query.query import run_query
 
from thefuzz import fuzz
 
from thefuzz import fuzz  # type: ignore
 

	
 
# NOTE: Statement doesn't seem to give us a running balance or a final total.
 

	
 
def standardize_amex_record(row):
 
def standardize_amex_record(row: Dict) -> Dict:
 
    return {
 
        'date': datetime.datetime.strptime(row['Date'], '%m/%d/%Y').date(),
...
 
@@ -26,5 +27,5 @@ def standardize_amex_record(row):
 

	
 

	
 
def standardize_beancount_record(row):
 
def standardize_beancount_record(row) -> Dict:  # type: ignore[no-untyped-def]
 
    return {
 
        'date': row.date,
...
 
@@ -34,13 +35,13 @@ 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}"
 

	
 

	
 
def sort_records(records):
 
def sort_records(records: List) -> List:
 
    return sorted(records, key=lambda x: (x['date'], x['amount']))
 

	
 

	
 
def records_match(r1, r2):
 
def records_match(r1: Dict, r2: Dict) -> Tuple[bool, str]:
 
    """Do these records represent the same transaction?"""
 
    date_matches = r1['date'] >= r2['date'] - datetime.timedelta(days=1) and r1['date'] <= r2['date'] + datetime.timedelta(days=1)
0 comments (0 inline, 0 general)