Skip to content

Commit

Permalink
ci: update mypy config and fix some errors
Browse files Browse the repository at this point in the history
also remove kjson, it's unused and don't think it's ever been used
  • Loading branch information
karlicoss committed Feb 10, 2025
1 parent 6d02733 commit 85ec9ad
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 142 deletions.
10 changes: 7 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ pretty = True
show_error_context = True
show_column_numbers = True
show_error_end = True
warn_redundant_casts = True
warn_unused_ignores = True

check_untyped_defs = True

# see https://mypy.readthedocs.io/en/stable/error_code_list2.html
warn_redundant_casts = True
strict_equality = True
enable_error_code = possibly-undefined
warn_unused_ignores = True
enable_error_code = deprecated,redundant-expr,possibly-undefined,truthy-bool,truthy-iterable,ignore-without-code,unused-awaitable


# not sure why mypy started discovering it (since 0.800??)
[mypy-hypothesis]
Expand Down
9 changes: 4 additions & 5 deletions src/promnesia/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def iter_all_visits(sources_subset: Iterable[str | int] = ()) -> Iterator[Res[Db
if name and is_subset_sources:
matched = name in sources_subset or i in sources_subset
if matched:
sources_subset -= {i, name} # type: ignore
sources_subset -= {i, name} # type: ignore[operator]
else:
logger.debug("skipping '%s' not in --sources.", name)
continue
Expand All @@ -79,7 +79,7 @@ def iter_all_visits(sources_subset: Iterable[str | int] = ()) -> Iterator[Res[Db
except Exception as e:
yield e

if sources_subset:
if sources_subset: # type: ignore[truthy-iterable]
logger.warning("unknown --sources: %s", ", ".join(repr(i) for i in sources_subset))


Expand Down Expand Up @@ -305,10 +305,9 @@ def cli_doctor_server(args: argparse.Namespace) -> None:

def _ordinal_or_name(s: str) -> str | int:
try:
s = int(s) # type: ignore
return int(s)
except ValueError:
pass
return s
return s


def main() -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/promnesia/cannon.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ def display(it, args) -> None: # pragma: no cover
import difflib
from sys import stdout

from termcolor import colored as C # type: ignore
from termcolor import colored as C # type: ignore[import-not-found]

for line in it:
line = line.strip()
Expand Down
4 changes: 2 additions & 2 deletions src/promnesia/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def get_tmpdir() -> tempfile.TemporaryDirectory[str]:

@lru_cache(None)
def _get_urlextractor(syntax: Syntax):
from urlextract import URLExtract # type: ignore
from urlextract import URLExtract # type: ignore[import-not-found]
u = URLExtract()
# https://github.com/lipoja/URLExtract/issues/13
if syntax in {'org', 'orgmode', 'org-mode'}: # TODO remove hardcoding..
Expand Down Expand Up @@ -414,7 +414,7 @@ def default_cache_dir() -> Path:
def _magic() -> Callable[[PathIsh], str | None]:
logger = get_logger()
try:
import magic # type: ignore
import magic # type: ignore[import-not-found]
except Exception as e:
logger.exception(e)
defensive_msg: str | None = None
Expand Down
122 changes: 0 additions & 122 deletions src/promnesia/kjson.py

This file was deleted.

7 changes: 4 additions & 3 deletions src/promnesia/sources/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ def _index(path: Path, opts: Options) -> Results:
mapper = map # dummy pool
else:
workers = None if cores == 0 else cores
pool = Pool(workers) # type: ignore
mapper = pool.map # type: ignore
pool = Pool(workers) # type: ignore[assignment]
mapper = pool.map # type: ignore[attr-defined]

# iterate over resolved paths, to avoid duplicates
def rit() -> Iterable[Path]:
Expand Down Expand Up @@ -359,7 +359,8 @@ def indexer() -> Urls | Results:
v = r

loc = v.locator
if loc is not None and root is not None:
# FIXME double checke that v.locator indeed can't be none and remove the check?
if loc is not None and root is not None: # type: ignore[redundant-expr]
# meh. but it works
# todo potentially, just use dataclasses instead...
loc = loc._replace(title=loc.title.replace(str(root) + os.sep, ''))
Expand Down
8 changes: 4 additions & 4 deletions src/promnesia/sources/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from pathlib import Path
from typing import NamedTuple

import mistletoe # type: ignore
import mistletoe.block_token as BT # type: ignore
from mistletoe.html_renderer import HTMLRenderer # type: ignore
from mistletoe.span_token import AutoLink, Link # type: ignore
import mistletoe # type: ignore[import-untyped]
import mistletoe.block_token as BT # type: ignore[import-untyped]
from mistletoe.html_renderer import HTMLRenderer # type: ignore[import-untyped]
from mistletoe.span_token import AutoLink, Link # type: ignore[import-untyped]

from promnesia.common import (
Extraction,
Expand Down
2 changes: 1 addition & 1 deletion src/promnesia/sources/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def connect_db(
yield db
finally:
try:
if db:
if db is not None:
db.close()
finally:
if decrypted_file and decrypted_file.exists():
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ commands =

[testenv:mypy-misc]
deps =
-e .[testing,HPI,org] # todo install from HPI[all] or something?
-e .[testing,HPI,org,markdown] # todo install from HPI[all] or something?
beautifulsoup4<4.13.0 # FIXME temporary hack until https://github.com/purarue/google_takeout_parser/pull/81 is merged
uv # for hpi module install
commands =
Expand Down

0 comments on commit 85ec9ad

Please sign in to comment.