Skip to content

Commit 5636b8f

Browse files
fix the return types of the classes' __enter__ functions (#384)
fix the return types of the classes' __enter__ functions so that the type information is preserved in context managers eg with-as blocks Signed-off-by: wyattscarpenter <[email protected]>
1 parent 6e0fb78 commit 5636b8f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/databricks/sql/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ def _set_use_inline_params_with_warning(self, value: Union[bool, str]):
271271

272272
return value
273273

274-
def __enter__(self):
274+
# The ideal return type for this method is perhaps Self, but that was not added until 3.11, and we support pre-3.11 pythons, currently.
275+
def __enter__(self) -> "Connection":
275276
return self
276277

277278
def __exit__(self, exc_type, exc_value, traceback):
@@ -409,7 +410,8 @@ def __init__(
409410
self.escaper = ParamEscaper()
410411
self.lastrowid = None
411412

412-
def __enter__(self):
413+
# The ideal return type for this method is perhaps Self, but that was not added until 3.11, and we support pre-3.11 pythons, currently.
414+
def __enter__(self) -> "Cursor":
413415
return self
414416

415417
def __exit__(self, exc_type, exc_value, traceback):

0 commit comments

Comments
 (0)