This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
v1.4.0
Deprecation
Constants
is deprecated as not necessary anymore with the newconst
.@factory
is deprecated in favor of@lazy
.
Features
-
@lazy
has been added to replace@factory
and theparameterized()
methods of bothFactory
andService
.from antidote import lazy, inject class Redis: pass @lazy # singleton by default def load_redis() -> Redis: return Redis() @inject def task(redis = load_redis()): ...
-
const
has been entirely reworked for better typing and ease of use:- it doesn't require
Constants
anymore. - environment variables are supported out of the box with
const.env
. - custom logic for retrieval can be defined with
@const.provider
.
Here's a rough overview:
from typing import Optional from antidote import const, injectable class Conf: THREADS = const(12) # static const PORT = const.env[int]() # converted to int automatically HOST = const.env("HOSTNAME") # define environment variable name explicitly, @injectable class Conf2: # stateful factory. It can also be stateless outside of Conf2. @const.provider def get(self, name: str, arg: Optional[str]) -> str: return arg or name DUMMY = get.const() NUMBER = get.const[int]("90") # value will be 90
- it doesn't require
-
@implements.overriding
overrides an existing implementation, and will be used in exactly the same conditions as the overridden one: default or not, predicates... -
@implements.by_default
defines a default implementation for an interface outside the weight system.
Experimental
const.converter
provides a similar to feature to the legacyauto_cast
fromConstants
.
Bug fix
- Better behavior of
inject
andworld.debug
with function wrappers, having a__wrapped__
attribute.