You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
async factories are supposed to be invoked using await Container.aget. However, currently there's nothing stopping a user from using the normal Container.get method. For example, this works for an async factory:
asyncdefint_factory():
awaitasyncio.sleep(0)
return42registry.register_factory(int, int_factory)
awaitcontainer.get(int) # obtains 42 even though the sync .get method was used
A user that doesn't know about aget might think all is well. But all is not well, since the value stored in the container is not 42 but the coroutine, which has now been awaited.
Solution could be to detect if .get is used for an async factory and raise an error. Luckily there already is the RegisteredService.is_async flag to help out with that
The text was updated successfully, but these errors were encountered:
async factories are supposed to be invoked using
await Container.aget
. However, currently there's nothing stopping a user from using the normalContainer.get
method. For example, this works for an async factory:A user that doesn't know about
aget
might think all is well. But all is not well, since the value stored in the container is not42
but the coroutine, which has now been awaited.Solution could be to detect if .
get
is used for an async factory and raise an error. Luckily there already is theRegisteredService.is_async
flag to help out with thatThe text was updated successfully, but these errors were encountered: