==================
Breaking static typing change
-----------------------------
- A function decorated with :py:func:`~.factory.factory` will not have the :code:`` operator
anymore from a static typing perspective. It's unfortunately not possible with the addition of
the class support for the decorator.
Deprecation
-----------
- :py:class:`.Service` and :py:class:`.ABCService` are deprecated in favor of :py:func:`.service`.
- Passing a function to the argument :code:`dependencies` of :py:func:`.inject` is deprecated.
If you want to customize how Antidote injects dependencies, just wrap :py:func:`.inject` instead.
- :py:func:`.inject`'s :code:`auto_provide` argument is deprecated. If you rely on this behavior,
wrap :py:func:`.inject`.
- :code:`world.lazy` is deprecated. It never brought a lot of value, one can easily write it oneself.
- :code:`dependency factory` and :code:`dependency implementation` are replaced by the more explicit
notation:
.. code-block:: python
world.get(dependency, source=factory)
inject(dependencies={'db': Get(dependency, source=factory)})
def (db):
...
- Annotation :code:`Provide` has been renamed :code:`Inject`.
- :code:`world.get` will not support extracting annotated dependencies anymore.
- Omitting the dependency when a type is specified in :code:`world.get` is deprecated. :code:`world.get`
provides now better type information.
.. code-block:: python
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 :code:`world.get` and :code:`const` have better type checking behavior, doing it only when
the specified type is an actual instance of :code:`type`. For protocols, type check will only
be done with those decorated with :code:`typing.runtime_checkable`.
- Dropped Python 3.6 support.
Features
--------
- Add :code:`ignore_type_hints` to :py:func:`.inject` to support cases when type hints cannot be
evaluated, typically in circular imports.
- Adding Markers for :py:func:`.inject` used as default arguments to declare injections:
.. code-block:: python
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