edgedb-python
edgedb-python copied to clipboard
Improve the Transaction docs to include patterns for unbound variables
Our current Transaction API makes it slightly more difficult to use variables bound within the transaction block, since linters and other static analysis tools cannot know that the iterator is every invoked on our transaction iterable. Given that, we should give better examples of how to deal with those tools, and explain more of the philosophy here.
Suggested pattern is:
my_var = None
async for tx in client.transaction():
async with tx:
my_var = …
assert my_var is not None
# use my_var without linter warnings or errors