Open
Description
Describe the bug
We have a statically typed dictionary that has values of type Cast[Decimal]
& it seems to be valid, since we cast column value to FLOAT
. But the type annotation expects two type arguments. I think it uses this stub: https://github.com/sqlalchemy/sqlalchemy2-stubs/blob/master/sqlalchemy-stubs/sql/elements.pyi#L333
whereas it's for a method cast
on ColumnElement
.
Expected behavior
Static typing using Cast[Decimal]
works fine :P
To Reproduce
from uuid import uuid4, UUID
from typing import Dict
from sqlalchemy.sql.elements import Cast
from decimal import Decimal
from sqlalchemy import FLOAT, cast
class X:
y: Optional[float]
x =x()
x.y = 2.0
payload: Dict[UUID, Cast[Decimal]] = {
uuid4(): cast(x.y, FLOAT)
}
Error
error: "Cast" expects 2 type arguments, but 1 given
Versions.
- OS: Linux Mint 19.3 Cinnamon
- Python: 3.7.10
- SQLAlchemy: 1.4.15
- Database: PostgreSQL
- DBAPI: asyncpg
Additional context
Maybe we should actually not use cast
in this case? We are using it because y
is an Optional[float]
& not float
, but we are 100% sure that it's not None
?
Have a nice day!