Skip to content

Commit 7eefb04

Browse files
authored
feat(Type Check): Added mypy (#78)
1 parent 5dfe8eb commit 7eefb04

16 files changed

Lines changed: 105 additions & 44 deletions

File tree

.github/workflows/check.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ jobs:
1717
run: uv sync --all-extras --dev
1818
- name: Lint with Ruff
1919
run: uv run ruff check .
20+
- name: Static type check with mypy
21+
run: uv run mypy fastapi_forge
2022
- name: Run tests
2123
run: uv run pytest tests -s -v

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ version: # Show the version of FastAPI Forge.
2020
lint: # Run linters on the codebase.
2121
uv run ruff format
2222
uv run ruff check . --fix --unsafe-fixes
23+
uv run mypy fastapi_forge
2324

2425
.PHONY: test
2526
test: # Run all tests in the codebase.

fastapi_forge/core/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import click
66

77
from fastapi_forge.logger import logger
8-
from fastapi_forge.project_io import ArtifactBuilder, create_fastapi_project_builder
8+
from fastapi_forge.project_io import ArtifactBuilder, create_fastapi_artifact_builder
99
from fastapi_forge.schemas import ProjectSpec
1010

1111
from .cookiecutter_adapter import (
@@ -23,7 +23,7 @@ def __init__(
2323
builder: ArtifactBuilder,
2424
template_processor: TemplateProcessor,
2525
template_generator: CookiecutterAdapter,
26-
template_resolver: Callable,
26+
template_resolver: Callable[[], Path],
2727
project_validator: ProjectValidator | None = None,
2828
):
2929
self.builder = builder
@@ -68,7 +68,7 @@ async def build_fastapi_project(
6868

6969
try:
7070
director = ProjectBuildDirector(
71-
builder=create_fastapi_project_builder(spec, dry_run=dry_run),
71+
builder=create_fastapi_artifact_builder(spec, dry_run=dry_run),
7272
project_validator=ProjectNameValidator(),
7373
template_processor=DefaultTemplateProcessor(),
7474
template_generator=template_generator,

fastapi_forge/example-projects/__init__.py

Whitespace-only changes.

fastapi_forge/project_io/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"ProjectLoader",
1111
"YamlProjectExporter",
1212
"YamlProjectLoader",
13-
"create_fastapi_project_builder",
13+
"create_fastapi_artifact_builder",
1414
"create_postgres_project_loader",
1515
"create_yaml_project_exporter",
1616
"load_from_database",
@@ -36,7 +36,7 @@ def load_from_database(conn_str: str, schema: str = "public") -> ProjectSpec:
3636
return DatabaseProjectLoader(inspector, schema).load()
3737

3838

39-
def create_fastapi_project_builder(
39+
def create_fastapi_artifact_builder(
4040
spec: ProjectSpec, dry_run: bool = False
4141
) -> FastAPIArtifactBuilder:
4242
return FastAPIArtifactBuilder(

fastapi_forge/project_io/database/postgres_inspector.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Any
12
from urllib.parse import urlparse
23

34
import psycopg2
@@ -38,7 +39,7 @@ def fetch_enums(self, schema: str) -> dict[str, list[str]]:
3839
)
3940
return dict(self.cursor.fetchall())
4041

41-
def fetch_enum_columns(self, schema: str) -> list[tuple]:
42+
def fetch_enum_columns(self, schema: str) -> list[tuple[Any, ...]]:
4243
self.cursor.execute(
4344
"""
4445
SELECT
@@ -65,7 +66,7 @@ def fetch_enum_columns(self, schema: str) -> list[tuple]:
6566
)
6667
return self.cursor.fetchall()
6768

68-
def fetch_schema_tables(self, schema: str) -> list[tuple]:
69+
def fetch_schema_tables(self, schema: str) -> list[tuple[Any, ...]]:
6970
self.cursor.execute(
7071
"""
7172
SELECT
@@ -146,7 +147,7 @@ def get_connection_string(self) -> str:
146147
def get_db_name(self) -> str:
147148
return self.db_name
148149

149-
def __del__(self):
150+
def __del__(self) -> None:
150151
if hasattr(self, "cursor"):
151152
self.cursor.close()
152153
if hasattr(self, "conn"):

fastapi_forge/project_io/database/protocols.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import abstractmethod
2-
from typing import Protocol
2+
from typing import Any, Protocol
33

44

55
class DatabaseInspector(Protocol):
@@ -12,11 +12,11 @@ def fetch_enums(self, schema: str) -> dict[str, list[str]]:
1212
raise NotImplementedError
1313

1414
@abstractmethod
15-
def fetch_enum_columns(self, schema: str) -> list[tuple]:
15+
def fetch_enum_columns(self, schema: str) -> list[tuple[Any, ...]]:
1616
raise NotImplementedError
1717

1818
@abstractmethod
19-
def fetch_schema_tables(self, schema: str) -> list[tuple]:
19+
def fetch_schema_tables(self, schema: str) -> list[tuple[Any, ...]]:
2020
raise NotImplementedError
2121

2222
@abstractmethod

fastapi_forge/project_io/database/schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def inspect_schema(self, schema: str = "public") -> SchemaInspectionResult:
4444
raise ValueError(f"Database error: {e}") from e
4545

4646
@staticmethod
47-
def _build_enum_usage(enum_columns: list[tuple]) -> dict[str, list[dict[str, Any]]]:
47+
def _build_enum_usage(
48+
enum_columns: list[tuple[Any, ...]],
49+
) -> dict[str, list[dict[str, Any]]]:
4850
usage: dict[str, list[dict[str, Any]]] = {}
4951
for schema, table, column, data_type, enum_type in enum_columns:
5052
if enum_type not in usage:

fastapi_forge/project_io/loader/database_loader.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def _create_model_from_table(
6262
self,
6363
table_name: str,
6464
table_name_full: str,
65-
columns_data: list[dict],
66-
enum_column_lookup: dict,
65+
columns_data: list[dict[str, Any]],
66+
enum_column_lookup: dict[str, str],
6767
) -> Model:
6868
fields = []
6969
relationships = []
@@ -101,7 +101,9 @@ def _create_model_from_table(
101101
return Model(name=table_name, fields=fields, relationships=relationships)
102102

103103
@staticmethod
104-
def _process_column_defaults(column: dict[str, Any], data_type: Any) -> tuple:
104+
def _process_column_defaults(
105+
column: dict[str, Any], data_type: Any
106+
) -> tuple[str | None, dict[str, Any] | None]:
105107
default = None
106108
extra_kwargs = None
107109

fastapi_forge/render/engines/jinja2_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class Jinja2Engine(TemplateEngine):
12-
def __init__(self):
12+
def __init__(self) -> None:
1313
self.env = Environment()
1414
self._register_core_filters()
1515

0 commit comments

Comments
 (0)