From 6caf620f88cb5b11b13985f247a30e732b3fdeb6 Mon Sep 17 00:00:00 2001 From: Yossi Rozantsev <54272821+Apakottur@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:15:30 -0400 Subject: [PATCH] Add missing overload to __add__ Add a missing `@overload` to the `__add__` operator. ### Description The `__add__` function is missing an overload that handles the rest of the cases, similar to the one that `__sub__` has a few lines later in the same file. This fix is taken from https://github.com/microsoft/pyright/issues/7743 ### Checklist This pull request is: - [x] A documentation / typographical / small typing error fix - Good to go, no issue or tests are needed - [ ] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. **Have a nice day!** Closes: #11307 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11307 Pull-request-sha: 961d87403a5f985fbd17e07bae490e8e97475158 Change-Id: I27784f79e8d4f8b7f09b17060186916c78cba0a3 (cherry picked from commit 18b5b8a5b4d40b8ed8695a4027cedaaafa04cff4) --- lib/sqlalchemy/sql/elements.py | 3 +++ test/typing/plain_files/sql/operators.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index bafb5c7786..24f04fd767 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -1065,6 +1065,9 @@ class SQLCoreOperations(Generic[_T_co], ColumnOperators, TypingOnly): other: Any, ) -> ColumnElement[str]: ... + @overload + def __add__(self, other: Any) -> ColumnElement[Any]: ... + def __add__(self, other: Any) -> ColumnElement[Any]: ... @overload diff --git a/test/typing/plain_files/sql/operators.py b/test/typing/plain_files/sql/operators.py index 2e2f31df9c..dbd6f3d48f 100644 --- a/test/typing/plain_files/sql/operators.py +++ b/test/typing/plain_files/sql/operators.py @@ -1,3 +1,4 @@ +import datetime as dt from decimal import Decimal from typing import Any from typing import List @@ -6,6 +7,7 @@ from sqlalchemy import ARRAY from sqlalchemy import BigInteger from sqlalchemy import column from sqlalchemy import ColumnElement +from sqlalchemy import func from sqlalchemy import Integer from sqlalchemy import select from sqlalchemy import String @@ -100,6 +102,10 @@ adds: "ColumnElement[str]" = A.string + A.string add1: "ColumnElement[int]" = A.id + A.id add2: "ColumnElement[int]" = A.id + 1 add3: "ColumnElement[int]" = 1 + A.id +add_date: "ColumnElement[dt.date]" = func.current_date() + dt.timedelta(days=1) +add_datetime: "ColumnElement[dt.datetime]" = ( + func.current_timestamp() + dt.timedelta(seconds=1) +) sub1: "ColumnElement[int]" = A.id - A.id sub2: "ColumnElement[int]" = A.id - 1 -- 2.47.2