Skip to content

Data type for Float column should be float, not Decimal #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 8 additions & 5 deletions sqlalchemy-stubs/sql/sqltypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,19 @@ class Numeric(_LookupExpressionAdapter, TypeEngine[decimal.Decimal]):
def result_processor(self, dialect: Dialect, coltype: Any) -> Optional[Callable[[Optional[Any]],
Optional[Union[float, decimal.Decimal]]]]: ...

class Float(Numeric):
class Float(_LookupExpressionAdapter, TypeEngine[float]):
__visit_name__: str = ...
scale: Optional[int] = ...
precision: Optional[int] = ...
asdecimal: bool = ...
scale: Optional[int] = ...
decimal_return_scale: Optional[int] = ...
asdecimal: bool = ...
def __init__(self, precision: Optional[int] = ..., asdecimal: bool = ...,
decimal_return_scale: Optional[int] = ..., **kwargs: Any) -> None: ...
def result_processor(self, dialect: Dialect, coltype: Any) -> Optional[Callable[[Optional[Any]],
Optional[Union[float, decimal.Decimal]]]]: ...
def literal_processor(self, dialect: Dialect) -> Callable[[float], str]: ...
@property
def python_type(self) -> Type[float]: ...
def bind_processor(self, dialect: Dialect) -> Optional[Callable[[Optional[str]], float]]: ...
def result_processor(self, dialect: Dialect, coltype: Any) -> Optional[Callable[[Optional[Any]], Optional[float]]]: ...

class DateTime(_LookupExpressionAdapter, TypeEngine[datetime]):
__visit_name__: str = ...
Expand Down
20 changes: 20 additions & 0 deletions test/test-data/sqlalchemy-sql-sqltypes.test
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,23 @@ main:6: error: No overload variant of "UnicodeText" matches argument types "int"
main:6: note: Possible overload variants:
main:6: note: def __init__(self, length: Optional[int] = ..., collation: Optional[str] = ..., convert_unicode: bool = ..., _warn_on_bytestring: bool = ...) -> UnicodeText
main:6: note: def __init__(self, length: Optional[int] = ..., collation: Optional[str] = ..., convert_unicode: str = ..., unicode_error: Optional[str] = ..., _warn_on_bytestring: bool = ...) -> UnicodeText

[case testFloatAndDecimal]
from decimal import Decimal
from sqlalchemy import Column, Float, Numeric, Integer
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Numbers(Base):
__tablename__ = "numbers"
id_ = Column(Integer, primary_key=True)

c_numeric = Column(Numeric, nullable=False)
c_float = Column(Float, nullable=False)

numbers_float = Numbers(c_numeric=1.0, c_float=1.0)
numbers_decimal = Numbers(c_numeric=Decimal(1.0), c_float=Decimal(1.0))
[out]
main:14: error: Incompatible type for "c_numeric" of "Numbers" (got "float", expected "Decimal")
main:15: error: Incompatible type for "c_float" of "Numbers" (got "Decimal", expected "float")