Releases: hynek/svcs
23.12.0
Added
- svcs now logs registrations at debug level along with a stacktrace. So if you ever get confused where your factories are coming from, set the log level to debug and trace your registrations!
Changed
-
Ooof. It's obvious in hindsight, but accessing anything directly on a request object like in the
request.svcs.get()
examples erases type information and everything becomes a big soup ofAny
.Therefore, we've added a new "best practice" for integrations to have a
svcs_from()
function that extracts containers from request objects (or from thread locals in the case of Flask).
23.11.0
23.10.0
Added
-
Proper documentation at https://svcs.hynek.me/!
I guess it's getting serious.
#17 -
Pyramid integration.
Please note that not all integrations will be shipped with svcs proper once it is stable.
Some will be moved to separate packages and Pyramid is a prime contender for that.
23.9.0
This is a huge release as far as breaking changes go and I hope the last one of such sorts.
There has always been the conundrum imposed by Python typing whether we a) support automatic type-deduction of the services or b) support abstract classes (ABCs, Protocols).
After lots of waffling, I've gone for a compromise: Container.(a)get()
are now properly typed as type[T] -> T
(for up to 10 services at once 😅). If you want T to be abstract (until Python typing changes its stance), you'll have to use Container.(a)get_abstract()
. The nice thing is that this separation serves more people and will be fully backwards-compatible, if we ever don't need it anymore.
Please see https://github.com/hynek/svcs#typing-caveats for more details and a more verbose explanation of the problem if you don't understand what any of the above means.
Full Changelog
Changed
Container.get()
andContainer.aget()
now have type hints that only work with concrete classes but allow for type checking without repeating yourself.
If you want to use abstract classes liketyping.Protocol
or ABCs, you can useContainer.get_abstract()
andContainer.aget_abstract()
instead.
Added
-
Container.get_abstract()
andContainer.aget_abstract()
.
They behave likeContainer.get()
andContainer.aget()
before. -
It is now possible to check if a service type is registered with a
Registry
by usingin
. -
It is now possible to check if a service type has a cached instance within a
Container
by usingin
. -
Registry
andContainer
are now also an (async) context managers that callclose()
/aclose()
on exit automatically.
23.8.0
23.7.0
23.6.0
23.5.0
23.4.0
23.3.0
Added
- Async method
Container.aget()
. This was necessary for generator-based cleanups. It works with sync factories too, so you can use it universally in async code. - Async method
ServicePing.aping()
. It works with sync factories and pings too, so you can use it universally in async code. #4
Changed
- Switched the cleanup mechanism from passing a function to allowing the factory to be a generator that yields the resource and can clean up after the
yield
. Just like Pytest fixtures. #3