Skip to content

Commit

Permalink
Fix type-checking failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisher87 committed Jun 19, 2024
1 parent 7e21f2c commit ecfeda0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/aross_stations_db/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@
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)

logger.success("Tables created")


@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)
Expand Down
9 changes: 6 additions & 3 deletions src/aross_stations_db/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions src/aross_stations_db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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']})"
4 changes: 2 additions & 2 deletions src/aross_stations_db/source_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand All @@ -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]

Expand Down

0 comments on commit ecfeda0

Please sign in to comment.