You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently when you access an attribute on a model, its type gets converted to the expected Python type. However, since this uses the plugin hook for attribute access, that means when structural typing is attempted, it doesn't match up.
Here's an example illustrating my point.
from typing_extensions import Protocol
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer
class UserStructure(Protocol):
id: int
Base = declarative_base()
class User(Base):
id = Column(Integer, primary_key=True)
user: UserStructure = User() # Incompatible types in assignment (expression has type "User", variable has type "UserStructure") [assignment]
# Following member(s) of "User" have conflicts:
# id: expected "int", got "Column[int]"
Even though reveal_type(user.id) shows int.
The text was updated successfully, but these errors were encountered:
Currently when you access an attribute on a model, its type gets converted to the expected Python type. However, since this uses the plugin hook for attribute access, that means when structural typing is attempted, it doesn't match up.
Here's an example illustrating my point.
Even though
reveal_type(user.id)
showsint
.The text was updated successfully, but these errors were encountered: