As the library already has a class, an open() method and a close() method, it would make sense to add the small steps needed to make it callable in a with statement. However, as it's a c-Extension I currently don't feel confident that I could write the code alone.
When the with statement is entered, the connection is opened. When it is left, the connection gets closed. Even in case of an exception. And just in case, the connection gets closed on object deletion as well.
As the library already has a class, an
open()
method and aclose()
method, it would make sense to add the small steps needed to make it callable in awith
statement. However, as it's a c-Extension I currently don't feel confident that I could write the code alone.In Python I would add this:
When the
with
statement is entered, the connection is opened. When it is left, the connection gets closed. Even in case of an exception. And just in case, the connection gets closed on object deletion as well.More explanation regarding the value of supporting
with
.Is there someone who has experience in transferring that idea to the C codebase here?
PS: Locally, I might simply add a wrapper class that gets the new methods added.