Skip to content

v1.4.0

Compare
Choose a tag to compare
@Finistere Finistere released this 22 May 19:32
· 10 commits to master since this release

Deprecation

  • Constants is deprecated as not necessary anymore with the new const.
  • @factory is deprecated in favor of @lazy.

Features

  • @lazy has been added to replace @factory and the parameterized() methods of both Factory and Service.

    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
  • @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 legacy auto_cast from Constants.

Bug fix

  • Better behavior of inject and world.debug with function wrappers, having a __wrapped__ attribute.