Skip to content

feat(python): implement runtime connection context manager hooks #3152 - #602

Open
abhibesu2018 wants to merge 1 commit into
duckdb:mainfrom
abhibesu2018:feature/python-context-manager-3152
Open

feat(python): implement runtime connection context manager hooks #3152#602
abhibesu2018 wants to merge 1 commit into
duckdb:mainfrom
abhibesu2018:feature/python-context-manager-3152

Conversation

@abhibesu2018

Copy link
Copy Markdown

📋 Overview
This PR addresses Issue #3152 by introducing native Context Manager support (with statements) to the DuckDB Python client.Currently, resource lifecycle management (such as registering/unregistering dataframes or view relations) requires manual tracking via tedious try...finally blocks. This update brings a much more idiomatic "Pythonic" approach to managing connections, database cursor states, and view registrations, reducing boilerplate code and preventing resource leaks.

🚀 Changes Made
DuckDBPyConnection.enter & exit: Added standard context manager hooks to automatically close connections/cursors or commit/rollback open transactions cleanly when exiting the scope.DuckDBPyConnection.register context support: Modified the relationship/view registration system so that invoking a registration inside a context manager automatically calls unregister() upon exit.Type Stubs Updated: Added matching method signatures to the target .pyi files to preserve flawless IDE autocompletion and static type checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant