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()` and `Container.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 like `typing.Protocol` or ABCs, you can use `Container.get_abstract()` and `Container.aget_abstract()` instead.
Added
- `Container.get_abstract()` and `Container.aget_abstract()`.
They behave like `Container.get()` and `Container.aget()` before.
- It is now possible to check if a service type is registered with a `Registry` by using `in`.
- It is now possible to check if a service type has a cached instance within a `Container` by using `in`.
- `Registry` and `Container` are now also an (async) context managers that call `close()` / `aclose()` on exit automatically.