Skip to content

Commit

Permalink
Fix typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Oct 6, 2023
1 parent dfa85e2 commit bd18ffa
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
9 changes: 4 additions & 5 deletions scripts/script_utils/fastapi_app_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

"""Used to define the location of the main FastAPI app object."""

# flake8: noqa

from typing import Any, Dict
from typing import Any

from fastapi import FastAPI

Expand All @@ -29,12 +27,13 @@
app.include_router(router)


def custom_openapi() -> Dict[str, Any]:
def custom_openapi() -> dict[str, Any]:
"""Get custom OpenAPI schema."""
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi_schema(app)
app.openapi_schema = openapi_schema
return app.openapi_schema


app.openapi = custom_openapi # type: ignore [assignment]
app.openapi = custom_openapi # type: ignore[method-assign]
2 changes: 1 addition & 1 deletion src/wps/adapters/inbound/fastapi_/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

def get_openapi_schema(api) -> dict[str, Any]:
"""Generate a custom OpenAPI schema for the service."""
config = Config() # pyright: ignore
config = Config() # type: ignore

return get_openapi(
title="Work Package Service",
Expand Down
6 changes: 3 additions & 3 deletions src/wps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def custom_openapi():
api.openapi_schema = openapi_schema
return api.openapi_schema

api.openapi = custom_openapi # type: ignore [assignment]
api.openapi = custom_openapi # type: ignore[method-assign]

return api


async def run_rest():
"""Run the HTTP REST API."""
config = Config() # pyright: ignore
config = Config() # type: ignore

async with get_container(config=config):
api = get_rest_api(config=config)
Expand All @@ -71,7 +71,7 @@ async def run_rest():

async def consume_events(run_forever: bool = True):
"""Run an event consumer listening to the configured topic."""
config = Config() # pyright: ignore
config = Config() # type: ignore

async with get_container(config=config) as container:
event_subscriber = await container.event_subscriber()
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def fixture_auth_context() -> AuthContext:
async def fixture_repository(mongodb_fixture: MongoDbFixture) -> WorkPackageRepository:
"""Fixture for creating a configured repository"""
work_package_config = WorkPackageConfig(
work_package_signing_key=SIGNING_KEY_PAIR.export_private() # pyright: ignore
work_package_signing_key=SIGNING_KEY_PAIR.export_private() # type: ignore
)
dataset_dao = await DatasetDaoConstructor.construct(
config=work_package_config,
Expand Down
10 changes: 5 additions & 5 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_work_order_token():
user_id="some-user-id",
user_public_crypt4gh_key="some-public-key",
full_user_name="Dr. John Doe",
email="[email protected]", # pyright: ignore
email="[email protected]", # type: ignore
)
assert token.full_user_name == "Dr. John Doe"

Expand Down Expand Up @@ -78,23 +78,23 @@ def test_bad_creation_data():
"""Test instantiating invalid work package creation DTO."""
with raises(ValidationError, match="dataset_id"):
WorkPackageCreationData(
dataset_id=["foo", "bar"], # pyright: ignore
dataset_id=["foo", "bar"], # type: ignore
type=WorkType.DOWNLOAD,
file_ids=["some-file-id", "another-file-id"],
user_public_crypt4gh_key=user_public_crypt4gh_key,
)
with raises(ValidationError, match="type"):
WorkPackageCreationData(
dataset_id="some-dataset-id",
type="UNKNOWN_TYPE", # pyright: ignore
type="UNKNOWN_TYPE", # type: ignore
file_ids=["some-file-id", "another-file-id"],
user_public_crypt4gh_key=user_public_crypt4gh_key,
)
with raises(ValidationError, match="file_ids"):
WorkPackageCreationData(
dataset_id="some-dataset-id",
type=WorkType.DOWNLOAD,
file_ids="some-file-id", # pyright: ignore
file_ids="some-file-id", # type: ignore
user_public_crypt4gh_key=user_public_crypt4gh_key,
)
with raises(ValidationError, match="user_public_crypt4gh_key"):
Expand All @@ -116,7 +116,7 @@ def test_work_package():
files={"some-file-id": ".sam", "another-file-id": ".bam"},
user_public_crypt4gh_key=user_public_crypt4gh_key,
full_user_name="Dr. John Doe",
email="[email protected]", # pyright: ignore
email="[email protected]", # type: ignore
token_hash="308eda9daf26b7446b284449a5895ab9a04ff30c129d4454e471cfb81bf5557d",
created=datetime(2022, 2, 2, 2, tzinfo=timezone.utc), # pyright: ignore
expires=datetime(2022, 2, 2, 3, tzinfo=timezone.utc), # pyright: ignore
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_sign_work_order_token():
user_id="some-user-id",
user_public_crypt4gh_key="some-public-key",
full_user_name="Dr. John Doe",
email="[email protected]", # pyright: ignore
email="[email protected]", # type: ignore
)
token_str = sign_work_order_token(work_order_token=work_order_token, key=key)
assert isinstance(token_str, str)
Expand Down

0 comments on commit bd18ffa

Please sign in to comment.