Skip to content
This repository was archived by the owner on Aug 10, 2024. It is now read-only.

V1.2.0

Choose a tag to compare

@Finistere Finistere released this 19 Apr 15:43
· 16 commits to master since this release

Bug fix

  • Fix injection error when using the Klass | None notation instead of Optional[Klass] in Python 3.10.

Features

  • frozen keyword argument to world.test.clone() which allows one to control whether the cloned world is already frozen or not.
  • Both inject.get and world.get now strictly follow the same API.
  • interface() and implements() which provide a cleaner way to separate implementations from the public interface. Qualifiers are also supported out of the box. They can be added with qualified_by keyword and requested with either qualified_by or qualified_by_one_of.
from antidote import implements, inject, interface, world, QualifiedBy

V1 = object()
V2 = object()


@interface
class Service:
    pass


@implements(Service).when(qualified_by=V1)
class ServiceImpl(Service):
    pass


@implements(Service).when(QualifiedBy(V2))
class ServiceImplV2(Service):
    pass


world.get[Service].single(qualified_by=V1)
world.get[Service].all()


@inject
def f(service: Service = inject.me(QualifiedBy(V2))) -> Service:
    return service


@inject
def f(services: list[Service] = inject.me(qualified_by=[V1, V2])) -> list[Service]:
    return services

Experimental

  • Predicate API is experimental allows you to define your custom logic for selecting the right implementation for a given interface. Qualifiers are implemented with the QualifiedBy predicate which is part of the public API.