]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixes: #11083 (#11095)
authorDaniel Robert <daniel.robert@acm.org>
Mon, 11 Mar 2024 21:34:20 +0000 (14:34 -0700)
committerFederico Caselli <cfederico87@gmail.com>
Mon, 11 Mar 2024 21:36:46 +0000 (22:36 +0100)
(cherry picked from commit 3551c7b66ab0318deef419fbe61fe038b6e2825c)

Change-Id: I959dff7f4ee6218267627e878283e3c48b88b314

lib/sqlalchemy/engine/util.py
test/typing/plain_files/orm/session.py

index 3d95ac586256a40452c1c74bd9d6dc54acdeb986..186ca4c32011e262c90452b1f8cf6319a65056d7 100644 (file)
@@ -17,6 +17,7 @@ from .. import exc
 from .. import util
 from ..util._has_cy import HAS_CYEXTENSION
 from ..util.typing import Protocol
+from ..util.typing import Self
 
 if typing.TYPE_CHECKING or not HAS_CYEXTENSION:
     from ._py_util import _distill_params_20 as _distill_params_20
@@ -113,7 +114,7 @@ class TransactionalContext:
                     "before emitting further commands."
                 )
 
-    def __enter__(self) -> TransactionalContext:
+    def __enter__(self) -> Self:
         subject = self._get_subject()
 
         # none for outer transaction, may be non-None for nested
index 0f1c35eafa13598e12b15e982388bbaf13088cbc..43fb17a75424c6207960207159bc476c40e0d660 100644 (file)
@@ -97,6 +97,12 @@ with Session(e) as sess:
         User.id
     ).offset(User.id)
 
+    # test #11083
+
+    with sess.begin() as tx:
+        # EXPECTED_TYPE: SessionTransaction
+        reveal_type(tx)
+
 # more result tests in typed_results.py