Skip to content

Commit

Permalink
ran mypy and fixed the errors
Browse files Browse the repository at this point in the history
  • Loading branch information
agennadi committed Nov 11, 2024
1 parent 8cabc0b commit 753c4e6
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: black --check .

- name: Type check with mypy
run: mypy .
run: mypy --config-file mypy.ini .

- name: Set up Node.js
uses: actions/setup-node@v3
Expand Down
16 changes: 14 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
repos:
- repo: https://github.com/psf/black
rev: 23.3.0 # use the latest version from PyPI
rev: 23.3.0
hooks:
- id: black
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.13.0'
hooks:
- id: mypy
args: ["--config-file", "mypy.ini"]
additional_dependencies:
- "pydantic>=2.9.0"
- "sqlalchemy>=2.0.35"
- "pydantic-settings>=2.5.2"
- "fastapi>=0.114.0"
- "GeoAlchemy2>=0.15.2"
- "pytest>=8.3.3"
File renamed without changes.
14 changes: 5 additions & 9 deletions backend/api/models/landslide_zones.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""All data of the Landslide Zones table from SFData."""

from sqlalchemy import String, Integer
from sqlalchemy import String, Integer, Float, DateTime, func
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from geoalchemy2 import Geometry
from datetime import datetime, DateTime
from datetime import datetime


class LandslideZones(DeclarativeBase):
Expand All @@ -22,17 +22,13 @@ class LandslideZones(DeclarativeBase):
sum_shape: Mapped[float] = mapped_column(Float)
shape_length: Mapped[float] = mapped_column(Float)
created_us: Mapped[str] = mapped_column(String)
created_da: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)
created_da: Mapped[datetime] = mapped_column(DateTime(timezone=True))
last_edited: Mapped[str] = mapped_column(String)
last_edi_1: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)
last_edi_1: Mapped[datetime] = mapped_column(DateTime(timezone=True))
shape_Le_1: Mapped[float] = mapped_column(Float)
shape_area: Mapped[float] = mapped_column(Float)
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
DateTime(timezone=True), server_default=func.now()
)

def __repr__(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions backend/api/models/liquefaction_zones.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""All data of the Liquefaction Zones table from SFData."""

from sqlalchemy import String
from sqlalchemy import String, Float, DateTime, func
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from geoalchemy2 import Geometry
from datetime import datetime, DateTime
from datetime import datetime


class LiquefactionZones(DeclarativeBase):
Expand All @@ -23,7 +23,7 @@ class LiquefactionZones(DeclarativeBase):
shape_length: Mapped[float] = mapped_column(Float)
shape_area: Mapped[float] = mapped_column(Float)
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
DateTime(timezone=True), server_default=func.now()
)

def __repr__(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions backend/api/models/neighborhoods.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Neighborhood boundaries in San Francisco"""

from sqlalchemy import String, Integer
from sqlalchemy import String, Integer, DateTime, func
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from geoalchemy2 import Geometry
from datetime import datetime, DateTime
from datetime import datetime


MAPPED_COLUMN_STRING_LENGTH = 200
Expand All @@ -22,7 +22,7 @@ class Neighborhoods(DeclarativeBase):
neighborhood: Mapped[str] = mapped_column(String(MAPPED_COLUMN_STRING_LENGTH))
geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326))
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utc_now
DateTime(timezone=True), server_default=func.now()
)

def __repr__(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions backend/api/models/seismic_hazard_zones.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""All data of the Seismic Hazard table from SFData."""

from sqlalchemy import Integer
from sqlalchemy import Integer, DateTime, func
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from geoalchemy2 import Geometry
from datetime import datetime, DateTime
from datetime import datetime


class SeismicHazardZones(DeclarativeBase):
Expand All @@ -19,7 +19,7 @@ class SeismicHazardZones(DeclarativeBase):
identifier: Mapped[int] = mapped_column(Integer, primary_key=True)
geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326))
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
DateTime(timezone=True), server_default=func.now()
)

def __repr__(self) -> str:
Expand Down
14 changes: 5 additions & 9 deletions backend/api/models/soft_story_properties.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""All data of the Soft Story table from SFData."""

from sqlalchemy import String, Integer
from sqlalchemy import String, Integer, DateTime, func
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from geoalchemy2 import Geometry
from datetime import datetime, DateTime
from datetime import datetime


MAPPED_COLUMN_STRING_LENGTH = 200
Expand All @@ -31,14 +31,10 @@ class SoftStoryProperties(DeclarativeBase):
status: Mapped[str] = mapped_column(String(MAPPED_COLUMN_STRING_LENGTH))
bos_district: Mapped[int] = mapped_column(Integer)
point: Mapped[Geometry] = mapped_column(Geometry("POINT", srid=4326))
sfdata_as_of: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)
sfdata_loaded_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
)
sfdata_as_of: Mapped[datetime] = mapped_column(DateTime(timezone=True))
sfdata_loaded_at: Mapped[datetime] = mapped_column(DateTime(timezone=True))
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
DateTime(timezone=True), server_default=func.now()
)

def __repr__(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions backend/api/models/tsunami.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Tsunami Risk Zone data"""

from sqlalchemy import String, Integer
from sqlalchemy import String, Integer, Float, DateTime, func
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from geoalchemy2 import Geometry
from datetime import datetime, DateTime
from datetime import datetime


MAPPED_COLUMN_STRING_LENGTH = 200
Expand All @@ -30,7 +30,7 @@ class TsunamiZones(DeclarativeBase):
# This data is ingested as PolygonZ but should be stored as MultiPolygon
geometry: Mapped[Geometry] = mapped_column(Geometry("MULTIPOLYGON", srid=4326))
update_timestamp: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=datetime.utcnow
DateTime(timezone=True), server_default=func.now()
)

def __repr__(self) -> str:
Expand Down
14 changes: 3 additions & 11 deletions backend/api/routers/combined_risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,15 @@ async def delete_combined_risks(address: str):
Remove the combined seismic risks of an address from
the database.
"""
pass
return {"message": "This endpoint is not yet implemented"}


@router.put("/{address}")
async def put_combined_risks(address: str, risks: dict):
"""
Add the combined seismic risks of an address to the database.
"""
pass


@router.post("/{address}")
async def put_combined_risks(address: str, risks: dict):
"""
Add the combined seismic risks of an address to the database.
"""
pass
return {"message": "This endpoint is not yet implemented"}


@router.get("/{address}")
Expand All @@ -42,4 +34,4 @@ async def get_combined_risks(address: str) -> dict:
three booleans.
"""
# TODO: Return a dictionary to avoid validation error
pass
return {"message": "This endpoint is not yet implemented"}
12 changes: 5 additions & 7 deletions backend/api/routers/polygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,34 @@
class Polygon(BaseModel):
"""GIS data container of vertices defining a polygon."""

pass


@router.delete("/{id}")
async def delete_polygon(id: int, table_name: str):
"""
Delete this polygon from that table.
"""
pass
return {"message": "This endpoint is not yet implemented"}


@router.put("/{id}")
async def put_polygon(id: int, polygon: Polygon, table_name: str):
"""
Put this polygon into that table.
"""
pass
return {"message": "This endpoint is not yet implemented"}


@router.post("/")
async def post_polygon(id: int, polygon: Polygon, table_name: str):
"""
Post this polygon to that table.
"""
pass
return {"message": "This endpoint is not yet implemented"}


@router.get("/{id}")
async def get_polygon(id: int, table_name: str) -> Polygon:
async def get_polygon(id: int, table_name: str):
"""
Get this polygon from that table.
"""
pass
return {"message": "This endpoint is not yet implemented"}
10 changes: 5 additions & 5 deletions backend/api/routers/reinforced_soft_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def delete_reinforced(address: str):
Check a small group of reinforced soft stories and raise an
exception if the building lacks an original soft story.
"""
pass
return {"message": "This endpoint is not yet implemented"}


@router.put("/{address}")
Expand All @@ -32,7 +32,7 @@ async def put_reinforced(
Check a small group of reinforced soft stories and raise an
exception if the building lacks an original soft story.
"""
pass
return {"message": "This endpoint is not yet implemented"}


@router.post("/{address}")
Expand All @@ -46,11 +46,11 @@ async def post_reinforced(
Check a small table of reinforced soft stories and raise an
exception if the building lacks an original soft story.
"""
pass
return {"message": "This endpoint is not yet implemented"}


@router.get("/{address}")
async def get_reinforced(address: str) -> bool:
async def get_reinforced(address: str):
"""
Return whether the building at an address, having a soft story,
has been reinforced.
Expand All @@ -59,4 +59,4 @@ async def get_reinforced(address: str) -> bool:
exception if the building lacks an original soft story.
"""
# TODO: Change return type to boolean to avoid validation error
pass
return {"message": "This endpoint is not yet implemented"}
4 changes: 2 additions & 2 deletions backend/api/routers/seismic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@


@router.get("/risk/{address}")
async def get_seismic_risk(address: str) -> bool:
async def get_seismic_risk(address: str):
"""
Return whether this address is in the current seismic risk
polygon.
"""
# TODO: Change return type to boolean to avoid validation error
pass
return {"message": "This endpoint is not yet implemented"}
10 changes: 5 additions & 5 deletions backend/api/routers/soft_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def delete_soft_story(address: str):
Delete the record that the building at an address has a soft
story.
"""
pass
return {"message": "This endpoint is not yet implemented"}


@router.put("/{address}")
Expand All @@ -26,7 +26,7 @@ async def put_soft_story(
Update whether the building at an address has a soft story
to the database.
"""
pass
return {"message": "This endpoint is not yet implemented"}


@router.post("/{address}")
Expand All @@ -37,13 +37,13 @@ async def post_soft_story(
Add that the building at an address has a soft story to the
database.
"""
pass
return {"message": "This endpoint is not yet implemented"}


@router.get("/{address}")
async def get_soft_story(address: str) -> bool:
async def get_soft_story(address: str):
"""
Return whether the building at an address has a soft story.
"""
# TODO: Change return type to boolean to avoid validation error
pass
return {"message": "This endpoint is not yet implemented"}
4 changes: 2 additions & 2 deletions backend/api/routers/tsunami.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@


@router.get("/risk/{address}")
async def get_risk(address: str) -> bool:
async def get_risk(address: str):
"""
Return whether this address is in the current tsunami risk
polygon.
"""
# TODO: Change return type to boolean to avoid validation error
pass
return {"message": "This endpoint is not yet implemented"}
2 changes: 1 addition & 1 deletion backend/api/tests/test_polygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from fastapi.testclient import TestClient
from ..schemas import Polygon
from ..index import app
from ..main import app


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion backend/database/tests/test_database.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from ...api.models.comined_risk import Base, CombinedRisk
from ...api.models.combined_risk import Base, CombinedRisk
from ...api.config import settings


Expand Down
7 changes: 7 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Global options:
[mypy]
plugins = pydantic.mypy, sqlalchemy.ext.mypy.plugin
ignore_missing_imports = True

[pytest]
addopts = --mypy
Loading

0 comments on commit 753c4e6

Please sign in to comment.