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

V1.3.0

Compare
Choose a tag to compare
@Finistere Finistere released this 26 Apr 18:46
· 14 commits to master since this release

Deprecation

  • @service is deprecated in favor of @injectable which is a drop-in replacement.
  • @inject used to raise a RuntimeError when specifying ignore_type_hints=True and no injections were found. It now raises NoInjectionsFoundError
  • Wiring.wire used to return the wired class, it won't be the case anymore.

Features

  • Add local type hint support with type_hints_locals argument for @inject, @injectable, @implements and @wire The default behavior can be configured globally with config Auto-detection is done through inspect and frame manipulation. It's mostly helpful inside tests.

    from __future__ import annotations
    
    from antidote import config, inject, injectable, world
    
    
    def function() -> None:
        @injectable
        class Dummy:
            pass
    
        @inject(type_hints_locals='auto')
        def f(dummy: Dummy = inject.me()) -> Dummy:
            return dummy
    
        assert f() is world.get(Dummy)
    
    
    function()
    
    config.auto_detect_type_hints_locals = True
    
    
    def function2() -> None:
        @injectable
        class Dummy:
            pass
    
        @inject
        def f(dummy: Dummy = inject.me()) -> Dummy:
            return dummy
    
        assert f() is world.get(Dummy)
    
    
    function2()
  • Add factory_method to @injectable (previous @service)

    from __future__ import annotations
    
    from antidote import injectable
    
    
    @injectable(factory_method='build')
    class Dummy:
        @classmethod
        def build(cls) -> Dummy:
            return cls()
  • Added ignore_type_hints argument to Wiring and @wire

  • Added type_hints_locals and class_in_localns argument to Wiring.wire

Bug fix

  • Fix Optional detection in predicate constraints.