-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
types #143
base: master
Are you sure you want to change the base?
types #143
Changes from all commits
d8bd30d
8983960
30b22b0
86b9a40
ef46de9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,7 +155,7 @@ def get_file(filename): | |
return _CACHE[filename] | ||
|
||
|
||
_CACHE = utils.DefaultDictWithKey(_FileMemo) | ||
_CACHE = utils.DefaultDictWithKey(_FileMemo) # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the ignore needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DefaultDictWithKey is not typed correctly - it inherits the types from defaultdict but takes a default function which takes one argument. Shall I add a comment explaining that? |
||
|
||
|
||
def cache(func=None, *, key=None): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
"""Utilities using petl. | ||
""" | ||
|
||
from typing import Optional | ||
from typing import Optional, Set | ||
import datetime | ||
import re | ||
|
||
import petl | ||
import petl # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this ignore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't look much further into it - is this file even supposed to be part of the package? petl doesn't seem to be listed in the dependencies |
||
|
||
from beancount.core import data | ||
from beancount.core import amount | ||
|
@@ -47,32 +47,33 @@ def table_to_directives( | |
metas.append((column, match.group(1))) | ||
|
||
# Create transactions. | ||
entries = [] | ||
entries: data.Entries = [] | ||
filename = filename or f"<{__file__}>" | ||
for index, rec in enumerate(table.records()): | ||
meta = data.new_metadata(filename, index) | ||
units = amount.Amount(rec.amount, currency) | ||
tags, links = set(), set() | ||
tags: Set[str] = set() | ||
links: Set[str] = set() | ||
link = getattr(rec, "link", None) | ||
if link: | ||
links.add(link) | ||
tag = getattr(rec, "tag", None) | ||
if tag: | ||
tags.add(tag) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely convinced that the type for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I stuck to the original code but I'm happy to refactor this as well |
||
txn = data.Transaction( | ||
meta, | ||
rec.date, | ||
flags.FLAG_OKAY, | ||
getattr(rec, "payee", None), | ||
getattr(rec, "narration", ""), | ||
tags, | ||
links, | ||
frozenset(tags), | ||
frozenset(links), | ||
[data.Posting(rec.account, units, None, None, None, None)], | ||
) | ||
if hasattr(rec, "other_account") and rec.other_account: | ||
txn.postings.append( | ||
data.Posting(rec.other_account, None, None, None, None, None) | ||
) | ||
link = getattr(rec, "link", None) | ||
if link: | ||
links.add(link) | ||
tag = getattr(rec, "tag", None) | ||
if tag: | ||
tags.add(tag) | ||
|
||
for column, key in metas: | ||
value = getattr(rec, column, None) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import datetime | ||
import decimal | ||
import unittest | ||
import petl | ||
import petl # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? |
||
|
||
from beancount.parser import cmptest | ||
from beangulp import petl_utils | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,10 +34,10 @@ def write_expected(outfile: TextIO, | |
name: The filename for filing, produced by the importer. | ||
entries: The list of entries extracted by the importer. | ||
""" | ||
date = date.isoformat() if date else '' | ||
formatted_date = date.isoformat() if date else '' | ||
name = name or '' | ||
print(f';; Account: {account}', file=outfile) | ||
print(f';; Date: {date}', file=outfile) | ||
print(f';; Date: {formatted_date}', file=outfile) | ||
print(f';; Name: {name}', file=outfile) | ||
printer.print_entries(entries, file=outfile) | ||
|
||
|
@@ -46,7 +46,7 @@ def write_expected_file(filepath: str, *data, force: bool = False): | |
"""Writes out the expected file.""" | ||
mode = 'w' if force else 'x' | ||
with open(filepath, mode) as expfile: | ||
write_expected(expfile, *data) | ||
write_expected(expfile, *data) # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expfile is |
||
|
||
|
||
def compare_expected(filepath: str, *data) -> List[str]: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
|
||
class Importer(csvbase.Importer): | ||
date = csvbase.Date('Posting Date', '%m/%d/%Y') | ||
date = csvbase.Date('Posting Date', '%m/%d/%Y') # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This date column shadows the date function of the importer protocol. Seems like the base class initialisation makes that all work but I don't know if this can be typed correctly. |
||
narration = csvbase.Columns('Description', 'Check or Slip #', sep='; ') | ||
amount = csvbase.Amount('Amount') | ||
balance = csvbase.Amount('Balance') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Python 3.9?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's the oldest supported version of Beancount - which version do you want?