Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

types #143

wants to merge 3 commits into from

Conversation

yagebu
Copy link
Member

@yagebu yagebu commented Jan 3, 2025

  • adjust types for a successful mypy run
  • ci: add mypy ci step

yagebu added 2 commits January 3, 2025 08:48
Some type: ignores were added but only internal uses of functionality.
@yagebu yagebu force-pushed the types branch 2 times, most recently from f4c3b0f to c4138e4 Compare January 3, 2025 08:03
@yagebu yagebu marked this pull request as ready for review January 3, 2025 08:18
@yagebu yagebu mentioned this pull request Jan 3, 2025
Copy link
Collaborator

@dnicolodi dnicolodi left a 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'
Copy link
Collaborator

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:
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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])
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants