44from typing import TYPE_CHECKING
55
66from _pytask .dag_utils import node_and_neighbors
7- from sqlalchemy import Column
87from sqlalchemy import create_engine
9- from sqlalchemy import String
10- from sqlalchemy .orm import declarative_base
8+ from sqlalchemy .orm import DeclarativeBase
9+ from sqlalchemy .orm import Mapped
10+ from sqlalchemy .orm import mapped_column
1111from sqlalchemy .orm import sessionmaker
1212
1313if TYPE_CHECKING :
2727DatabaseSession = sessionmaker ()
2828
2929
30- BaseTable = declarative_base ()
30+ class BaseTable (DeclarativeBase ):
31+ pass
3132
3233
33- class State (BaseTable ): # type: ignore[valid-type, misc]
34+ class State (BaseTable ):
3435 """Represent the state of a node in relation to a task."""
3536
3637 __tablename__ = "state"
3738
38- task = Column ( String , primary_key = True )
39- node = Column ( String , primary_key = True )
40- hash_ = Column ( String )
39+ task : Mapped [ str ] = mapped_column ( primary_key = True )
40+ node : Mapped [ str ] = mapped_column ( primary_key = True )
41+ hash_ : Mapped [ str ]
4142
4243
4344def create_database (url : str ) -> None :
@@ -54,7 +55,7 @@ def _create_or_update_state(first_key: str, second_key: str, hash_: str) -> None
5455 if not state_in_db :
5556 session .add (State (task = first_key , node = second_key , hash_ = hash_ ))
5657 else :
57- state_in_db .hash_ = hash_ # type: ignore[assignment]
58+ state_in_db .hash_ = hash_
5859 session .commit ()
5960
6061
0 commit comments