From 64f8c1936be240152decd9a15f7d13936e5aaac8 Mon Sep 17 00:00:00 2001 From: Johan Lundberg Date: Wed, 18 Feb 2026 13:08:03 +0100 Subject: [PATCH] refactor: fix lint warnings and remove stale type: ignore comments --- .gitignore | 3 +++ src/porchlight/app.py | 2 +- src/porchlight/cli.py | 4 +-- tests/test_client_registration.py | 43 +++++++++++++++++-------------- tests/test_config.py | 10 +++---- 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 5542551..40b4925 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ wheels/ # Git worktrees .worktrees/ + +# Runtime data +data/ diff --git a/src/porchlight/app.py b/src/porchlight/app.py index 3cc1881..f0bc34f 100644 --- a/src/porchlight/app.py +++ b/src/porchlight/app.py @@ -91,7 +91,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]: def create_app(settings: Settings | None = None) -> FastAPI: if settings is None: - settings = Settings() # type: ignore[call-arg] + settings = Settings() app = FastAPI( title="Porchlight", diff --git a/src/porchlight/cli.py b/src/porchlight/cli.py index 6bc5f7a..30a4d5b 100644 --- a/src/porchlight/cli.py +++ b/src/porchlight/cli.py @@ -52,7 +52,7 @@ def create_invite( note: Annotated[str | None, typer.Option(help="Optional note stored with the link")] = None, ) -> None: """Generate a magic link registration URL for a new user.""" - settings = Settings() # type: ignore[call-arg] + settings = Settings() effective_ttl = ttl if ttl is not None else settings.invite_ttl url = asyncio.run(_create_invite(settings, username, effective_ttl, note)) typer.echo(url) @@ -64,7 +64,7 @@ def initial_admin( group: Annotated[list[str] | None, typer.Option(help="Groups to assign (repeatable)")] = None, ) -> None: """Bootstrap the first admin user with a registration link.""" - settings = Settings() # type: ignore[call-arg] + settings = Settings() groups = group if group is not None else ["admin", "users"] url = asyncio.run(_initial_admin(settings, username, groups)) typer.echo(url) diff --git a/tests/test_client_registration.py b/tests/test_client_registration.py index 59a2cf7..d1d7e2b 100644 --- a/tests/test_client_registration.py +++ b/tests/test_client_registration.py @@ -19,23 +19,24 @@ scope = ["openid", "profile"] toml_file = tmp_path / "test.toml" toml_file.write_text(toml_content) - settings = Settings(_toml_file=str(toml_file)) # type: ignore[call-arg] + settings = Settings(_toml_file=str(toml_file)) app = create_app(settings) - async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client: - # Trigger lifespan - async with app.router.lifespan_context(app): - response = await client.get("/health") - assert response.status_code == 200 + async with ( + AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client, + app.router.lifespan_context(app), + ): + response = await client.get("/health") + assert response.status_code == 200 - oidc_server = app.state.oidc_server - assert "test-rp" in oidc_server.context.cdb - cdb_entry = oidc_server.context.cdb["test-rp"] - assert cdb_entry["client_id"] == "test-rp" - assert cdb_entry["client_secret"] == "test-secret-0123456789abcdef" - assert ("https://app.example.com/callback", {}) in cdb_entry["redirect_uris"] - assert cdb_entry["scope"] == ["openid", "profile"] - assert cdb_entry["allowed_scopes"] == ["openid", "profile"] + oidc_server = app.state.oidc_server + assert "test-rp" in oidc_server.context.cdb + cdb_entry = oidc_server.context.cdb["test-rp"] + assert cdb_entry["client_id"] == "test-rp" + assert cdb_entry["client_secret"] == "test-secret-0123456789abcdef" + assert ("https://app.example.com/callback", {}) in cdb_entry["redirect_uris"] + assert cdb_entry["scope"] == ["openid", "profile"] + assert cdb_entry["allowed_scopes"] == ["openid", "profile"] async def test_manage_app_always_registered() -> None: @@ -43,10 +44,12 @@ async def test_manage_app_always_registered() -> None: settings = Settings(issuer="https://test.example.com") app = create_app(settings) - async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client: - async with app.router.lifespan_context(app): - response = await client.get("/health") - assert response.status_code == 200 + async with ( + AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client, + app.router.lifespan_context(app), + ): + response = await client.get("/health") + assert response.status_code == 200 - oidc_server = app.state.oidc_server - assert "manage-app" in oidc_server.context.cdb + oidc_server = app.state.oidc_server + assert "manage-app" in oidc_server.context.cdb diff --git a/tests/test_config.py b/tests/test_config.py index c006602..8a91127 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -39,7 +39,7 @@ def test_settings_from_env(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("OIDC_OP_ISSUER", "https://op.example.org") monkeypatch.setenv("OIDC_OP_STORAGE_BACKEND", "mongodb") monkeypatch.setenv("OIDC_OP_MONGODB_URI", "mongodb://remote:27017") - settings = Settings() # type: ignore[call-arg] + settings = Settings() assert settings.issuer == "https://op.example.org" assert settings.storage_backend == StorageBackend.MONGODB @@ -58,7 +58,7 @@ scope = ["openid", "profile"] toml_file = tmp_path / "test.toml" toml_file.write_text(toml_content) - settings = Settings(_toml_file=str(toml_file)) # type: ignore[call-arg] + settings = Settings(_toml_file=str(toml_file)) assert settings.issuer == "https://toml.example.com" assert settings.debug is True assert settings.sqlite_path == "custom/path.db" @@ -80,13 +80,13 @@ debug = false monkeypatch.setenv("OIDC_OP_ISSUER", "https://env.example.com") monkeypatch.setenv("OIDC_OP_DEBUG", "true") - settings = Settings(_toml_file=str(toml_file)) # type: ignore[call-arg] + settings = Settings(_toml_file=str(toml_file)) assert settings.issuer == "https://env.example.com" assert settings.debug is True def test_missing_toml_file_uses_defaults() -> None: - settings = Settings(issuer="http://localhost:8000", _toml_file="/nonexistent/path.toml") # type: ignore[call-arg] + settings = Settings(issuer="http://localhost:8000", _toml_file="/nonexistent/path.toml") assert settings.issuer == "http://localhost:8000" assert settings.clients == {} @@ -96,5 +96,5 @@ def test_config_file_env_var_override(tmp_path: Path, monkeypatch: pytest.Monkey toml_file.write_text('issuer = "https://custom-path.example.com"\n') monkeypatch.setenv("OIDC_OP_CONFIG_FILE", str(toml_file)) - settings = Settings() # type: ignore[call-arg] + settings = Settings() assert settings.issuer == "https://custom-path.example.com"