Skip to content

Add enter, exit function #537

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

Merged
merged 1 commit into from
Feb 27, 2025
Merged
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
4 changes: 2 additions & 2 deletions tests/unit/test_dbapi.py
Original file line number Diff line number Diff line change
@@ -312,5 +312,5 @@ def test_hostname_parsing():

def test_description_is_none_when_cursor_is_not_executed():
connection = Connection("sample_trino_cluster:443")
cursor = connection.cursor()
assert hasattr(cursor, 'description')
with connection.cursor() as cursor:
assert hasattr(cursor, 'description')
6 changes: 6 additions & 0 deletions trino/dbapi.py
Original file line number Diff line number Diff line change
@@ -382,6 +382,12 @@ def __init__(
def __iter__(self):
return self._iterator

def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
self.close()

@property
def connection(self):
return self._connection