typing: Annotate Iterators more specifically.
This commit is contained in:
parent
999ca2c5e1
commit
bd0d607032
4 changed files with 6 additions and 6 deletions
|
@ -293,13 +293,13 @@ class Posting(BasePosting):
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_txn(cls, txn: Transaction) -> Iterable['Posting']:
|
def from_txn(cls, txn: Transaction) -> Iterator['Posting']:
|
||||||
"""Yield an enhanced Posting object for every posting in the transaction"""
|
"""Yield an enhanced Posting object for every posting in the transaction"""
|
||||||
for index, post in enumerate(txn.postings):
|
for index, post in enumerate(txn.postings):
|
||||||
yield cls.from_beancount(txn, index, post)
|
yield cls.from_beancount(txn, index, post)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_entries(cls, entries: Iterable[Directive]) -> Iterable['Posting']:
|
def from_entries(cls, entries: Iterable[Directive]) -> Iterator['Posting']:
|
||||||
"""Yield an enhanced Posting object for every posting in these entries"""
|
"""Yield an enhanced Posting object for every posting in these entries"""
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
# Because Beancount's own Transaction class isn't type-checkable,
|
# Because Beancount's own Transaction class isn't type-checkable,
|
||||||
|
|
|
@ -22,7 +22,7 @@ from typing import (
|
||||||
AbstractSet,
|
AbstractSet,
|
||||||
Any,
|
Any,
|
||||||
Dict,
|
Dict,
|
||||||
Iterable,
|
Iterator,
|
||||||
List,
|
List,
|
||||||
Optional,
|
Optional,
|
||||||
Set,
|
Set,
|
||||||
|
@ -93,7 +93,7 @@ class HookRegistry:
|
||||||
for mod_name, hook_names in self.INCLUDED_HOOKS.items():
|
for mod_name, hook_names in self.INCLUDED_HOOKS.items():
|
||||||
self.import_hooks(mod_name, *(hook_names or []), package=self.__module__)
|
self.import_hooks(mod_name, *(hook_names or []), package=self.__module__)
|
||||||
|
|
||||||
def group_by_directive(self, config_str: str='') -> Iterable[Tuple[HookName, Type[Hook]]]:
|
def group_by_directive(self, config_str: str='') -> Iterator[Tuple[HookName, Type[Hook]]]:
|
||||||
config_str = config_str.strip()
|
config_str = config_str.strip()
|
||||||
if not config_str:
|
if not config_str:
|
||||||
config_str = 'all'
|
config_str = 'all'
|
||||||
|
|
|
@ -259,7 +259,7 @@ class _RequireLinksPostingMetadataHook(_PostingHook):
|
||||||
txn: Transaction,
|
txn: Transaction,
|
||||||
post: data.Posting,
|
post: data.Posting,
|
||||||
keys: Sequence[MetaKey],
|
keys: Sequence[MetaKey],
|
||||||
) -> Iterable[errormod.InvalidMetadataError]:
|
) -> Iterator[errormod.InvalidMetadataError]:
|
||||||
have_docs = False
|
have_docs = False
|
||||||
for key in keys:
|
for key in keys:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -143,7 +143,7 @@ class RelatedPostings(Sequence[data.Posting]):
|
||||||
def clear(self) -> None:
|
def clear(self) -> None:
|
||||||
self._postings.clear()
|
self._postings.clear()
|
||||||
|
|
||||||
def iter_with_balance(self) -> Iterable[Tuple[data.Posting, Balance]]:
|
def iter_with_balance(self) -> Iterator[Tuple[data.Posting, Balance]]:
|
||||||
balance = MutableBalance()
|
balance = MutableBalance()
|
||||||
for post in self:
|
for post in self:
|
||||||
balance.add_amount(post.units)
|
balance.add_amount(post.units)
|
||||||
|
|
Loading…
Reference in a new issue