-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Use context managers to manage cleanups #29
Conversation
At first glance,this Looks like it |
thanks for the quick feedback! |
Asyncness is still detectable, by the incoming function Type Additionally normal Generators Are not awaitabe |
How? The usual ways using iscoroutinefunction and issyncgenfunction both return False. |
Also fun fact, I've run into problems immediately with this approach and had to add an |
It May be a good idea to separate factories and contexts on the registration level |
That's not really the problem (so far). It's just that independently from how factories represented internally, a factory may return a context manager and the question is what to do with it. Just return it? Means you have to write boilerplate like this for all of them: def factory():
with Engine.connect() as conn:
yield conn This was the previous behavior. If you always enter them, you lose control over when they entered. My personal example where that did something I didn't want is my unit of work transaction manager. It's really just a trade-off between convenience and surprise whether |
Makes us better Python citizens and allows to pass context managers like
sqlalalchemy.Engine.connect
directly as factories.Only downside is that we can't detect the async-ness of factories anymore because an async context manager function is a sync function that returns an async object…
Is this what you had in mind @RonnyPfannschmidt?