This repository was archived by the owner on Aug 10, 2024. It is now read-only.
v1.4.0
Deprecation
Constantsis deprecated as not necessary anymore with the newconst.@factoryis deprecated in favor of@lazy.
Features
-
@lazyhas been added to replace@factoryand theparameterized()methods of bothFactoryandService.from antidote import lazy, inject class Redis: pass @lazy # singleton by default def load_redis() -> Redis: return Redis() @inject def task(redis = load_redis()): ...
-
consthas been entirely reworked for better typing and ease of use:- it doesn't require
Constantsanymore. - 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.overridingoverrides an existing implementation, and will be used in exactly the same conditions as the overridden one: default or not, predicates... -
@implements.by_defaultdefines a default implementation for an interface outside the weight system.
Experimental
const.converterprovides a similar to feature to the legacyauto_castfromConstants.
Bug fix
- Better behavior of
injectandworld.debugwith function wrappers, having a__wrapped__attribute.