]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add missing overload to __add__
authorYossi Rozantsev <54272821+Apakottur@users.noreply.github.com>
Wed, 24 Apr 2024 20:15:30 +0000 (16:15 -0400)
committerFederico Caselli <cfederico87@gmail.com>
Fri, 26 Apr 2024 19:21:12 +0000 (21:21 +0200)
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: #<issue number>` 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: #<issue number>` 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
test/typing/plain_files/sql/operators.py

index bafb5c77860047cac7ff208872e6ad1588e22844..24f04fd76702dfff804d050bc053456e1509bc2a 100644 (file)
@@ -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
index 2e2f31df9cf5fd3942b5725743c27508c9ea972c..dbd6f3d48f42f5b0fddff5a30d8fee418f687980 100644 (file)
@@ -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