setup: Enable stricter type checking.
This caught the "return instead of raise" bug in meta_project.
This commit is contained in:
parent
d9dca2cd68
commit
e6894c2b46
3 changed files with 16 additions and 7 deletions
|
@ -43,7 +43,7 @@ class MetaProject(core._NormalizePostingMetadataHook):
|
||||||
def __init__(self, config: configmod.Config, source_path: Path=PROJECT_DATA_PATH) -> None:
|
def __init__(self, config: configmod.Config, source_path: Path=PROJECT_DATA_PATH) -> None:
|
||||||
repo_path = config.repository_path()
|
repo_path = config.repository_path()
|
||||||
if repo_path is None:
|
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
|
project_data_path = repo_path / source_path
|
||||||
source = {'filename': str(project_data_path)}
|
source = {'filename': str(project_data_path)}
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -37,6 +37,7 @@ from typing import (
|
||||||
RTId = Union[int, str]
|
RTId = Union[int, str]
|
||||||
TicketAttachmentIds = Tuple[str, Optional[str]]
|
TicketAttachmentIds = Tuple[str, Optional[str]]
|
||||||
_LinkCache = MutableMapping[TicketAttachmentIds, Optional[str]]
|
_LinkCache = MutableMapping[TicketAttachmentIds, Optional[str]]
|
||||||
|
_URLLookup = Callable[..., Optional[str]]
|
||||||
|
|
||||||
class RTLinkCache(_LinkCache):
|
class RTLinkCache(_LinkCache):
|
||||||
"""Cache RT links to disk
|
"""Cache RT links to disk
|
||||||
|
@ -125,7 +126,8 @@ class RTLinkCache(_LinkCache):
|
||||||
|
|
||||||
def __len__(self) -> int:
|
def __len__(self) -> int:
|
||||||
cursor = self._db.execute('SELECT COUNT(*) FROM RTLinkCache')
|
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]:
|
def __getitem__(self, key: TicketAttachmentIds) -> Optional[str]:
|
||||||
if key in self._nourls:
|
if key in self._nourls:
|
||||||
|
@ -134,11 +136,12 @@ class RTLinkCache(_LinkCache):
|
||||||
'SELECT url FROM RTLinkCache WHERE ticket_id = ? AND attachment_id IS ?',
|
'SELECT url FROM RTLinkCache WHERE ticket_id = ? AND attachment_id IS ?',
|
||||||
key,
|
key,
|
||||||
)
|
)
|
||||||
retval = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
if retval is None:
|
if row is None:
|
||||||
raise KeyError(key)
|
raise KeyError(key)
|
||||||
else:
|
else:
|
||||||
return retval[0]
|
retval: str = row[0]
|
||||||
|
return retval
|
||||||
|
|
||||||
def __setitem__(self, key: TicketAttachmentIds, value: Optional[str]) -> None:
|
def __setitem__(self, key: TicketAttachmentIds, value: Optional[str]) -> None:
|
||||||
if value is 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
|
# mypy complains that the first argument isn't self, but this isn't meant
|
||||||
# to be a method, it's just an internal decrator.
|
# 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)
|
@functools.wraps(func)
|
||||||
def caching_wrapper(self,
|
def caching_wrapper(self,
|
||||||
ticket_id: RTId,
|
ticket_id: RTId,
|
||||||
attachment_id: Optional[RTId]=None,
|
attachment_id: Optional[RTId]=None,
|
||||||
) -> str:
|
) -> Optional[str]:
|
||||||
cache_key = (str(ticket_id), attachment_id and str(attachment_id))
|
cache_key = (str(ticket_id), attachment_id and str(attachment_id))
|
||||||
|
url: Optional[str]
|
||||||
try:
|
try:
|
||||||
url = self._cache[cache_key]
|
url = self._cache[cache_key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
|
@ -3,5 +3,10 @@ test=pytest
|
||||||
typecheck=pytest --addopts="--mypy conservancy_beancount"
|
typecheck=pytest --addopts="--mypy conservancy_beancount"
|
||||||
|
|
||||||
[mypy]
|
[mypy]
|
||||||
|
disallow_any_unimported = True
|
||||||
show_error_codes = True
|
show_error_codes = True
|
||||||
|
strict_equality = True
|
||||||
|
warn_redundant_casts = True
|
||||||
|
warn_return_any = True
|
||||||
|
warn_unreachable = True
|
||||||
warn_unused_configs = True
|
warn_unused_configs = True
|
||||||
|
|
Loading…
Reference in a new issue