diff --git a/conservancy_beancount/plugin/meta_project.py b/conservancy_beancount/plugin/meta_project.py index cde952dff5d29634d22ba3ff3ceabdbe4f60f22e..343a10046bccf1c31247f38b60c15b057d6ab57d 100644 --- a/conservancy_beancount/plugin/meta_project.py +++ b/conservancy_beancount/plugin/meta_project.py @@ -43,7 +43,7 @@ class MetaProject(core._NormalizePostingMetadataHook): def __init__(self, config: configmod.Config, source_path: Path=PROJECT_DATA_PATH) -> None: repo_path = config.repository_path() if repo_path is None: - return self._config_error("no repository configured") + raise self._config_error("no repository configured") project_data_path = repo_path / source_path source = {'filename': str(project_data_path)} try: diff --git a/conservancy_beancount/rtutil.py b/conservancy_beancount/rtutil.py index 906e79582beba0b1c8e85f1738b2b620e79ea3a8..cb2dd371de43b906db49cdf4f532716a79b0133f 100644 --- a/conservancy_beancount/rtutil.py +++ b/conservancy_beancount/rtutil.py @@ -37,6 +37,7 @@ from typing import ( RTId = Union[int, str] TicketAttachmentIds = Tuple[str, Optional[str]] _LinkCache = MutableMapping[TicketAttachmentIds, Optional[str]] +_URLLookup = Callable[..., Optional[str]] class RTLinkCache(_LinkCache): """Cache RT links to disk @@ -125,7 +126,8 @@ class RTLinkCache(_LinkCache): def __len__(self) -> int: cursor = self._db.execute('SELECT COUNT(*) FROM RTLinkCache') - return cursor.fetchone()[0] + len(self._nourls) + count: int = cursor.fetchone()[0] + return count + len(self._nourls) def __getitem__(self, key: TicketAttachmentIds) -> Optional[str]: if key in self._nourls: @@ -134,11 +136,12 @@ class RTLinkCache(_LinkCache): 'SELECT url FROM RTLinkCache WHERE ticket_id = ? AND attachment_id IS ?', key, ) - retval = cursor.fetchone() - if retval is None: + row = cursor.fetchone() + if row is None: raise KeyError(key) else: - return retval[0] + retval: str = row[0] + return retval def __setitem__(self, key: TicketAttachmentIds, value: Optional[str]) -> None: if value is None: @@ -191,13 +194,14 @@ class RT: # mypy complains that the first argument isn't self, but this isn't meant # to be a method, it's just an internal decrator. - def _cache_method(func: Callable) -> Callable: # type:ignore[misc] + def _cache_method(func: _URLLookup) -> _URLLookup: # type:ignore[misc] @functools.wraps(func) def caching_wrapper(self, ticket_id: RTId, attachment_id: Optional[RTId]=None, - ) -> str: + ) -> Optional[str]: cache_key = (str(ticket_id), attachment_id and str(attachment_id)) + url: Optional[str] try: url = self._cache[cache_key] except KeyError: diff --git a/setup.cfg b/setup.cfg index cd889309418564c3c27c1ead2e061a851b9d8385..c7858f35b788256d5b94c5b5750e12b5c8a5a75d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,5 +3,10 @@ test=pytest typecheck=pytest --addopts="--mypy conservancy_beancount" [mypy] +disallow_any_unimported = True show_error_codes = True +strict_equality = True +warn_redundant_casts = True +warn_return_any = True +warn_unreachable = True warn_unused_configs = True