Changeset - e6894c2b4693
[Not reviewed]
0 3 0
Brett Smith - 4 years ago 2020-03-29 23:39:09
brettcsmith@brettcsmith.org
setup: Enable stricter type checking.

This caught the "return instead of raise" bug in meta_project.
3 files changed with 16 insertions and 7 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/meta_project.py
Show inline comments
...
 
@@ -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:
conservancy_beancount/rtutil.py
Show inline comments
...
 
@@ -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:
setup.cfg
Show inline comments
...
 
@@ -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
0 comments (0 inline, 0 general)