Skip to content
Open

Ty #954

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
34d43f4
anyio==4.13.0
armanddidierjean Apr 12, 2026
a07e75c
Async file manipulation with anyio
armanddidierjean Apr 12, 2026
0f8df1b
Remove aiofiles
armanddidierjean Apr 12, 2026
668294b
Format
armanddidierjean Apr 12, 2026
2bc1252
Don't use async methods in computed properties
armanddidierjean Apr 12, 2026
57cae54
Fix
armanddidierjean Apr 12, 2026
bc08d8b
Format
armanddidierjean Apr 12, 2026
7a20a23
Fix tests
armanddidierjean Apr 12, 2026
b32e7d6
Ruff 0.15.10
armanddidierjean Apr 12, 2026
3867c81
Remove Ruff target-version
armanddidierjean Apr 12, 2026
474a50c
Format
armanddidierjean Apr 12, 2026
bc40670
Fix lint
armanddidierjean Apr 12, 2026
2fa146c
Remove circular import in module permissions
armanddidierjean Apr 12, 2026
a0b20b0
Don't import module from tests in raid tests
armanddidierjean Apr 12, 2026
0aa6990
Use StrEnum
armanddidierjean Apr 12, 2026
a2f65b5
Use Special type parameter syntax
armanddidierjean Apr 12, 2026
e9b83fb
Use Special type parameter syntax
armanddidierjean Apr 12, 2026
72a3cd5
Sort imports
armanddidierjean Apr 12, 2026
c3b349f
Ignore weasyprint import
armanddidierjean Apr 12, 2026
fc04d2c
Add ty==0.0.29
armanddidierjean Apr 12, 2026
fbd4618
Fix type
armanddidierjean Apr 12, 2026
7975b92
Ignore Google API
armanddidierjean Apr 13, 2026
3fdf32f
Fix ty issues
armanddidierjean Apr 13, 2026
da6b5ed
Ignore ty known issue
armanddidierjean Apr 13, 2026
201da42
Make some column non nullable in Seed
armanddidierjean Apr 13, 2026
a26518d
Run Ty in CI
armanddidierjean Apr 13, 2026
e2f95e8
Fix warnings
armanddidierjean Apr 13, 2026
c0acdc6
Fix thick_columns for Sport Competition
armanddidierjean Apr 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/lintandformat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
ruff check --output-format=github
ruff format --check

- name: Type checking using Ty
run: ty check --output-format=github --error=all

- name: Cache .mypy_cache folder
id: mypy_cache
uses: actions/cache@v4.3.0
Expand Down
8 changes: 4 additions & 4 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import uuid
from collections.abc import AsyncGenerator, Awaitable, Callable
from contextlib import asynccontextmanager
from pathlib import Path
from typing import TYPE_CHECKING

import alembic.command as alembic_command
import alembic.config as alembic_config
import alembic.migration as alembic_migration
from anyio import Path
from calypsso import get_calypsso_app
from fastapi import FastAPI, HTTPException, Request, Response, status
from fastapi.encoders import jsonable_encoder
Expand Down Expand Up @@ -475,7 +475,7 @@ async def init_google_API(
pass


def test_configuration(
async def test_configuration(
settings: Settings,
hyperion_error_logger: logging.Logger,
) -> None:
Expand All @@ -499,8 +499,8 @@ def test_configuration(
)

# Create folder for calendars if they don't already exists
Path("data/ics/").mkdir(parents=True, exist_ok=True)
Path("data/core/").mkdir(parents=True, exist_ok=True)
await Path("data/ics/").mkdir(parents=True, exist_ok=True)
await Path("data/core/").mkdir(parents=True, exist_ok=True)


async def init_lifespan(
Expand Down
17 changes: 8 additions & 9 deletions app/core/core_endpoints/endpoints_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path

from anyio import Path
from fastapi import APIRouter, Depends, Request
from fastapi.responses import FileResponse

Expand Down Expand Up @@ -51,7 +50,7 @@ async def read_privacy(settings: Settings = Depends(get_settings)):
"""

return patch_identity_in_text(
Path("assets/privacy.txt").read_text(encoding="utf-8"),
await Path("assets/privacy.txt").read_text(encoding="utf-8"),
settings,
)

Expand All @@ -66,7 +65,7 @@ async def read_terms_and_conditions(settings: Settings = Depends(get_settings)):
"""

return patch_identity_in_text(
Path("assets/terms-and-conditions.txt").read_text(encoding="utf-8"),
await Path("assets/terms-and-conditions.txt").read_text(encoding="utf-8"),
settings,
)

Expand All @@ -80,7 +79,7 @@ async def read_mypayment_tos(settings: Settings = Depends(get_settings)):
Return MyPayment latest ToS
"""
return patch_identity_in_text(
Path("assets/mypayment-terms-of-service.txt").read_text(encoding="utf-8"),
await Path("assets/mypayment-terms-of-service.txt").read_text(encoding="utf-8"),
settings,
)

Expand All @@ -95,7 +94,7 @@ async def read_support(settings: Settings = Depends(get_settings)):
"""

return patch_identity_in_text(
Path("assets/support.txt").read_text(encoding="utf-8"),
await Path("assets/support.txt").read_text(encoding="utf-8"),
settings,
)

Expand All @@ -109,7 +108,7 @@ async def read_security_txt(settings: Settings = Depends(get_settings)):
Return Hyperion security.txt file
"""
return patch_identity_in_text(
Path("assets/security.txt").read_text(encoding="utf-8"),
await Path("assets/security.txt").read_text(encoding="utf-8"),
settings,
)

Expand All @@ -124,7 +123,7 @@ async def read_wellknown_security_txt(settings: Settings = Depends(get_settings)
"""

return patch_identity_in_text(
Path("assets/security.txt").read_text(encoding="utf-8"),
await Path("assets/security.txt").read_text(encoding="utf-8"),
settings,
)

Expand All @@ -139,7 +138,7 @@ async def read_robots_txt(settings: Settings = Depends(get_settings)):
"""

return patch_identity_in_text(
Path("assets/robots.txt").read_text(encoding="utf-8"),
await Path("assets/robots.txt").read_text(encoding="utf-8"),
settings,
)

Expand Down
11 changes: 6 additions & 5 deletions app/core/google_api/google_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from types import TracebackType
from typing import Self

from fastapi import HTTPException, Request
from google.auth.transport import requests
Expand Down Expand Up @@ -217,7 +218,7 @@ def __init__(self, db: AsyncSession, settings: Settings):
self._db = db
self._settings = settings

async def __aenter__(self) -> "DriveGoogleAPI":
async def __aenter__(self) -> Self:
google_api = GoogleAPI()
creds = await google_api.get_credentials(self._db, self._settings)
self._drive: Resource = build("drive", "v3", credentials=creds)
Expand Down Expand Up @@ -245,7 +246,7 @@ def create_folder(self, folder_name: str, parent_folder_id: GoogleId) -> GoogleI
"mimeType": "application/vnd.google-apps.folder",
"parents": [parent_folder_id],
}
response = self._drive.files().create(body=file_metadata).execute()
response = self._drive.files().create(body=file_metadata).execute() # ty:ignore[unresolved-attribute]
folder_id: GoogleId = response.get("id")
return folder_id

Expand All @@ -269,7 +270,7 @@ async def upload_file(
mimetype=mimetype,
)
response = (
self._drive.files().create(body=file_metadata, media_body=media).execute()
self._drive.files().create(body=file_metadata, media_body=media).execute() # ty:ignore[unresolved-attribute]
)
uploaded_file_id: GoogleId = response.get("id")
return uploaded_file_id
Expand All @@ -287,12 +288,12 @@ def replace_file(
mimetype="application/pdf",
)
response = (
self._drive.files()
self._drive.files() # ty:ignore[unresolved-attribute]
.update(fileId=file_id, body=file_metadata, media_body=media)
.execute()
)
result: GoogleId = response.get("id")
return result

def delete_file(self, file_id: GoogleId) -> None:
self._drive.files().delete(fileId=file_id).execute()
self._drive.files().delete(fileId=file_id).execute() # ty:ignore[unresolved-attribute]
6 changes: 3 additions & 3 deletions app/core/groups/groups_type.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class GroupType(str, Enum):
class GroupType(StrEnum):
"""
In Hyperion, each user may have multiple groups. Belonging to a group gives access to a set of specific permissions.

Expand All @@ -14,7 +14,7 @@ class GroupType(str, Enum):
admin = "0a25cb76-4b63-4fd3-b939-da6d9feabf28"


class AccountType(str, Enum):
class AccountType(StrEnum):
"""
Various account types that can be created in Hyperion.
Each account type is associated with a set of permissions.
Expand Down
7 changes: 4 additions & 3 deletions app/core/mypayment/endpoints_mypayment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import urllib.parse
import uuid
from datetime import UTC, datetime, timedelta
from pathlib import Path
from uuid import UUID

import calypsso
from anyio import Path
from fastapi import (
APIRouter,
BackgroundTasks,
Expand Down Expand Up @@ -1493,7 +1493,7 @@ async def get_user_tos(
accepted_tos_version=existing_user_payment.accepted_tos_version,
latest_tos_version=LATEST_TOS,
tos_content=patch_identity_in_text(
Path("assets/mypayment-terms-of-service.txt").read_text("utf-8"),
await Path("assets/mypayment-terms-of-service.txt").read_text("utf-8"),
settings,
),
max_wallet_balance=settings.MYPAYMENT_MAXIMUM_WALLET_BALANCE,
Expand Down Expand Up @@ -2683,6 +2683,7 @@ async def refund_transaction(
)

if wallet_previously_credited.user is not None:
wallet_previously_debited_name: str = "Unknown"
if wallet_previously_debited.user is not None:
wallet_previously_debited_name = wallet_previously_debited.user.full_name
elif wallet_previously_debited.store is not None:
Expand Down Expand Up @@ -2944,7 +2945,7 @@ async def download_invoice(
status_code=403,
detail="User is not allowed to access this invoice",
)
return get_file_from_data(
return await get_file_from_data(
directory="mypayment/invoices",
filename=str(invoice_id),
)
Expand Down
18 changes: 9 additions & 9 deletions app/core/mypayment/types_mypayment.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
from enum import Enum
from enum import StrEnum
from uuid import UUID


class WalletType(str, Enum):
class WalletType(StrEnum):
USER = "user"
STORE = "store"


class WalletDeviceStatus(str, Enum):
class WalletDeviceStatus(StrEnum):
INACTIVE = "inactive"
ACTIVE = "active"
REVOKED = "revoked"


class TransactionType(str, Enum):
class TransactionType(StrEnum):
DIRECT = "direct"
REQUEST = "request"
REFUND = "refund"


class HistoryType(str, Enum):
class HistoryType(StrEnum):
TRANSFER = "transfer"
RECEIVED = "received"
GIVEN = "given"
REFUND_CREDITED = "refund_credited"
REFUND_DEBITED = "refund_debited"


class TransactionStatus(str, Enum):
class TransactionStatus(StrEnum):
"""
CONFIRMED: The transaction has been confirmed and is complete.
CANCELED: The transaction has been canceled. It is used for transfer requests, for which the user has 15 minutes to complete the HelloAsso checkout
Expand All @@ -41,17 +41,17 @@ class TransactionStatus(str, Enum):
PENDING = "pending"


class RequestStatus(str, Enum):
class RequestStatus(StrEnum):
PROPOSED = "proposed"
ACCEPTED = "accepted"
REFUSED = "refused"


class TransferType(str, Enum):
class TransferType(StrEnum):
HELLO_ASSO = "hello_asso"


class ActionType(str, Enum):
class ActionType(StrEnum):
TRANSFER = "transfer"
REFUND = "refund"
CANCEL = "cancel"
Expand Down
Loading
Loading