Skip to content

Commit a57ddba

Browse files
fix chapter 6 ruff errors without changing behavior
Modernize type annotations and the UTC alias, and mark the unused lifespan parameter explicitly. Generated with [Snowflake CoCo](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code) Co-authored-by: Snowflake CoCo <noreply@snowflake.com>
1 parent b1ce612 commit a57ddba

6 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎Chapter06/registration-service/alembic/versions/21e17247292d_add_user_preferences.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
"""
88

9-
from typing import Sequence, Union
9+
from collections.abc import Sequence
1010

1111
import sqlalchemy as sa
1212
from sqlalchemy.dialects import postgresql
@@ -15,9 +15,9 @@
1515

1616
# revision identifiers, used by Alembic.
1717
revision: str = "21e17247292d"
18-
down_revision: Union[str, Sequence[str], None] = "911c97e9e02f"
19-
branch_labels: Union[str, Sequence[str], None] = None
20-
depends_on: Union[str, Sequence[str], None] = None
18+
down_revision: str | Sequence[str] | None = "911c97e9e02f"
19+
branch_labels: str | Sequence[str] | None = None
20+
depends_on: str | Sequence[str] | None = None
2121

2222

2323
def upgrade() -> None:

‎Chapter06/registration-service/alembic/versions/911c97e9e02f_create_users_table.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
77
"""
88

9-
from typing import Sequence, Union
9+
from collections.abc import Sequence
1010

1111
import sqlalchemy as sa
1212

1313
from alembic import op
1414

1515
# revision identifiers, used by Alembic.
1616
revision: str = "911c97e9e02f"
17-
down_revision: Union[str, Sequence[str], None] = None
18-
branch_labels: Union[str, Sequence[str], None] = None
19-
depends_on: Union[str, Sequence[str], None] = None
17+
down_revision: str | Sequence[str] | None = None
18+
branch_labels: str | Sequence[str] | None = None
19+
depends_on: str | Sequence[str] | None = None
2020

2121

2222
def upgrade() -> None:

‎Chapter06/registration-service/database.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
)
2626

2727

28-
async def get_db() -> AsyncGenerator[AsyncSession, None]:
28+
async def get_db() -> AsyncGenerator[AsyncSession]:
2929
async with async_session() as session:
3030
yield session

‎Chapter06/registration-service/main.py‎

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

1515

1616
@asynccontextmanager
17-
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
17+
async def lifespan(_app: FastAPI) -> AsyncGenerator[None]:
1818
yield
1919
await engine.dispose()
2020

‎Chapter06/registration-service/models.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime, timezone
1+
from datetime import UTC, datetime
22

33
from sqlalchemy import JSON, Boolean, DateTime, Integer, String
44
from sqlalchemy.dialects.postgresql import JSONB
@@ -43,7 +43,7 @@ class User(Base):
4343
)
4444
created_at: Mapped[datetime] = mapped_column(
4545
DateTime(timezone=True),
46-
default=lambda: datetime.now(timezone.utc),
46+
default=lambda: datetime.now(UTC),
4747
)
4848

4949
preferences: Mapped[dict | None] = mapped_column(

‎Chapter06/registration-service/test_main.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
)
3434

3535

36-
async def override_get_db() -> AsyncGenerator[AsyncSession, None]:
36+
async def override_get_db() -> AsyncGenerator[AsyncSession]:
3737
async with session_factory() as session:
3838
yield session
3939

@@ -42,7 +42,7 @@ async def override_get_db() -> AsyncGenerator[AsyncSession, None]:
4242

4343

4444
@pytest.fixture(autouse=True)
45-
def database() -> Generator[None, None, None]:
45+
def database() -> Generator[None]:
4646
Base.metadata.create_all(schema_engine)
4747
yield
4848
Base.metadata.drop_all(schema_engine)

0 commit comments

Comments
 (0)