v1.1.0
Breaking static typing change
- A function decorated with
@factory
will not have the@
operator anymore from a static typing perspective. It's unfortunately not possible with the addition of the class support for the decorator.
Deprecation
-
Service
andABCService
are deprecated in favor of@service
. -
Passing a function to the argument
dependencies
of@inject
is deprecated. If you want to customize how Antidote injects dependencies, just wrap@inject
instead. -
@inject
'sauto_provide
argument is deprecated. If you rely on this behavior, wrap@inject
. -
world.lazy
is deprecated. It never brought a lot of value, one can easily write it oneself. -
dependency @ factory
anddependency @ implementation
are replaced by the more explicit notation:world.get(dependency, source=factory) @inject(dependencies={'db': Get(dependency, source=factory)}) def (db): ...
-
Annotation
Provide
has been renamedInject
. -
world.get
will not support extracting annotated dependencies anymore. -
Omitting the dependency when a type is specified in
world.get
is deprecated.world.get
provides now better type information.from antidote import world, service @service class Dummy: pass # this will expose the correct type: world.get(Dummy) # so this is deprecated world.get[Dummy]() # you can still specify the type explicitly world.get[Dummy](Dummy)
Change
- Both
world.get
andconst
have better type checking behavior, doing it only when the specified type is an actual instance oftype
. For protocols, type check will only be done with those decorated with@typing.runtime_checkable
. - Dropped Python 3.6 support.
Features
-
Add
ignore_type_hints
to@inject
to support cases when type hints cannot be evaluated, typically in circular imports. -
Adding Markers for
@inject
used as default arguments to declare injections:from antidote import const, Constants, factory, inject, service class Config(Constants): HOST = const[str]("host") @service class Dummy: value: str @factory def dummy_factory() -> Dummy: return Dummy() # inject type hint @inject def f(dummy: Dummy = inject.me()) -> Dummy: return dummy # inject type hint with factory @inject def f2(dummy: Dummy = inject.me(source=dummy_factory)) -> Dummy: return dummy # inject constants @inject def f3(host: str = Config.HOST) -> str: return host # inject a dependency explicitly @inject def f4(x=inject.get(Dummy)) -> Dummy: return x # inject a dependency with a factory explicitly @inject def f5(x=inject.get(Dummy, source=dummy_factory)) -> Dummy: return x