-
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
Conversation
yagebu
commented
Jan 3, 2025
- adjust types for a successful mypy run
- ci: add mypy ci step
Some type: ignores were added but only internal uses of functionality.
f4c3b0f
to
c4138e4
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?
@@ -257,7 +258,7 @@ def _importer(importer): | |||
|
|||
|
|||
class Ingest: | |||
def __init__(self, importers, hooks=None): | |||
def __init__(self, importers: Sequence[Union[Importer, ImporterProtocol]], hooks: Optional[Sequence[Any]] = 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.
hooks: Optional[Sequence[Any]]
could at least be hooks: Optional[Sequence[Callable]]
@@ -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?
"""See Importer class name property.""" | ||
return f"{self.__class__.__module__}.{self.__class__.__name__}" | ||
|
||
__str__ = name | ||
|
||
def identify(self, file) -> bool: | ||
"""See Importer class identify() method.""" | ||
# Type error ignore for backwards compatibility - this should be overridden | ||
# and implemented in subclasses | ||
return None # 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.
If returning None
is not allowed, return None
should be raise NotImplementedError
. If it is allowed, the annotation is wrong.
|
||
def file_account(self, file) -> data.Account: | ||
"""See Importer class account() method.""" | ||
# Type error ignore for backwards compatibility - this should be overridden | ||
# and implemented in subclasses | ||
return None # 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.
Same.
@@ -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?
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.
@@ -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.