-
Notifications
You must be signed in to change notification settings - Fork 35
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
Conversation
yagebu
commented
Jan 3, 2025
- adjust types for a successful mypy run
- ci: add mypy ci step
c4138e4
to
0b55392
Compare
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.
I'm not convinced that adding types to the examples is a good idea. The examples are supposed to be as simple as possible and serve as templates for inexperienced programmers. Adding typing annotations seems to only add complexity for very little gain.
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '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.
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?
@@ -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 comment
The 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 comment
The 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?
@@ -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 comment
The 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 comment
The 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.
examples/importers/utrade.py
Outdated
index = 0 | ||
with open(filepath) as infile: | ||
for index, row in enumerate(csv.DictReader(infile)): | ||
meta = data.new_metadata(filepath, index) | ||
date = parse(row['DATE']).date() | ||
rtype = row['TYPE'] | ||
link = f"ut{row['REF #']}" | ||
links = frozenset([link]) |
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.
These two lines can be one line.
@@ -122,9 +123,9 @@ def extract(self, filepath, existing): | |||
rate = D(match.group(3)) | |||
|
|||
if rtype == 'BUY': | |||
cost = position.Cost(rate, self.currency, None, None) | |||
cost = position.CostSpec(rate, None, self.currency, None, None, None) |
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? Cost
should be just fine.
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.
a Cost requires a date (the booking code will insert it for all postings, falling back to the entry date)
@@ -143,11 +144,11 @@ def extract(self, filepath, existing): | |||
logging.error("Missing cost basis in '%s'", row['DESCRIPTION']) | |||
continue | |||
cost_number = D(match.group(1)) | |||
cost = position.Cost(cost_number, self.currency, None, None) | |||
cost = position.CostSpec(cost_number, None, self.currency, None, None, None) |
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.
Here too.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely convinced that the type for links
and tags
should be frozenset
and not simply collections.abc.Set
. Anyhow, This seems a very convoluted way to crete a frozenset
of one element.
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.
I stuck to the original code but I'm happy to refactor this as well
Some type: ignores were added but only internal uses of functionality.