diff --git a/src/aross_stations_db/cli.py b/src/aross_stations_db/cli.py index 3f8f1b0..f24e19c 100644 --- a/src/aross_stations_db/cli.py +++ b/src/aross_stations_db/cli.py @@ -12,16 +12,18 @@ get_stations, ) -config = Settings() +# TODO: False-positive. Remove type-ignore. +# See: https://github.com/pydantic/pydantic/issues/6713 +config = Settings() # type:ignore[call-arg] @click.group() -def cli(): +def cli() -> None: pass @cli.command -def init(): +def init() -> None: """Create the database tables.""" create_tables(config.db_session) @@ -29,7 +31,7 @@ def init(): @cli.command -def load(): +def load() -> None: """Load the database tables from files on disk.""" stations = get_stations(config.stations_metadata_filepath) events = get_events(config.events_dir) diff --git a/src/aross_stations_db/config.py b/src/aross_stations_db/config.py index 8e11420..8aa4f05 100644 --- a/src/aross_stations_db/config.py +++ b/src/aross_stations_db/config.py @@ -16,17 +16,20 @@ class Settings(BaseSettings): DATA_BASEDIR: DirectoryPath DB_CONNSTR: PostgresDsn - @computed_field + # TODO: Specifically ignore this type of error instead of using type-ignore; but + # mypy doesn't yet categorize this error in its own type, so we need to wait for a + # release, likely 1.11: https://github.com/python/mypy/pull/16571/files + @computed_field # type:ignore[misc] @cached_property def events_dir(self) -> DirectoryPath: return self.DATA_BASEDIR / "events" - @computed_field + @computed_field # type:ignore[misc] @cached_property def stations_metadata_filepath(self) -> FilePath: return self.DATA_BASEDIR / "metadata" / "aross.asos_stations.metadata.csv" - @computed_field + @computed_field # type:ignore[misc] @cached_property def db_session(self) -> Session: engine = create_engine(str(self.DB_CONNSTR)) diff --git a/src/aross_stations_db/db.py b/src/aross_stations_db/db.py index 414cd93..ddd5fd7 100644 --- a/src/aross_stations_db/db.py +++ b/src/aross_stations_db/db.py @@ -17,7 +17,7 @@ def create_tables(session: Session) -> None: Base.metadata.create_all(session.get_bind()) -def load_stations(stations: Iterator[dict], *, session: Session) -> None: +def load_stations(stations: list[dict[str, str]], *, session: Session) -> None: session.add_all( [ Station( @@ -32,7 +32,7 @@ def load_stations(stations: Iterator[dict], *, session: Session) -> None: session.commit() -def load_events(events: Iterator[dict], *, session: Session) -> None: +def load_events(events: Iterator[dict[str, str]], *, session: Session) -> None: session.add_all( [ Event( @@ -46,5 +46,5 @@ def load_events(events: Iterator[dict], *, session: Session) -> None: session.commit() -def _station_location_wkt(station: dict) -> str: +def _station_location_wkt(station: dict[str, str]) -> str: return f"SRID=4326;POINT({station['longitude']} {station['latitude']})" diff --git a/src/aross_stations_db/source_data.py b/src/aross_stations_db/source_data.py index 0e9b454..8b0cc1f 100644 --- a/src/aross_stations_db/source_data.py +++ b/src/aross_stations_db/source_data.py @@ -4,7 +4,7 @@ from pathlib import Path -def get_stations(metadata_fp: Path) -> list[dict]: +def get_stations(metadata_fp: Path) -> list[dict[str, str]]: stations_metadata_str = metadata_fp.read_text() return list(csv.DictReader(io.StringIO(stations_metadata_str))) @@ -13,7 +13,7 @@ def get_event_files(events_dir: Path) -> Iterator[Path]: return events_dir.glob("*.event.csv") -def get_events(events_dir: Path) -> Iterator[dict]: +def get_events(events_dir: Path) -> Iterator[dict[str, str]]: for event_fp in get_event_files(events_dir): station_id = event_fp.stem.split(".")[0]