New `CustomField` syntax to support classes injection:
python class Header(CustomField): def use( self, /, <- new thing **kwargs ): kwargs = super().use(**kwargs) kwargs[self.param_name] = kwargs["headers"][self.param_name] return kwargs
* docs: fix typo by Lancetnik in https://github.com/Lancetnik/FastDepends/pull/36 * fix: support custom fields for classes injection by Lancetnik in https://github.com/Lancetnik/FastDepends/pull/39 * chore: drop python3.7 support
What's Changed Now you can use **FastDepends** to inject dependencies to your class constructors and/or methods!
python from fast_depends import Depends, inject
def get_var(): return 1
class Class: inject def __init__(self, a = Depends(get_var)) -> None: self.a = a
inject def calc(self, a = Depends(get_var)) -> int: return a + self.a
assert Class().calc() == 2
* build(deps-dev): bump ruff from 0.1.5 to 0.1.6 by dependabot in https://github.com/Lancetnik/FastDepends/pull/28 * build(deps-dev): bump mypy from 1.7.0 to 1.7.1 by dependabot in https://github.com/Lancetnik/FastDepends/pull/29 * build(deps): bump pypa/gh-action-pypi-publish from 1.8.10 to 1.8.11 by dependabot in https://github.com/Lancetnik/FastDepends/pull/30 * build(deps-dev): bump ruff from 0.1.6 to 0.1.7 by dependabot in https://github.com/Lancetnik/FastDepends/pull/33 * build(deps-dev): bump isort from 5.12.0 to 5.13.0 by dependabot in https://github.com/Lancetnik/FastDepends/pull/32 * build(deps): bump actions/setup-python from 4 to 5 by dependabot in https://github.com/Lancetnik/FastDepends/pull/31 * feat (34): inject to classes by Lancetnik in https://github.com/Lancetnik/FastDepends/pull/35
What's Changed * chore: downloads/month badge by Lancetnik in https://github.com/Lancetnik/FastDepends/pull/14 * build(deps): bump actions/cache from 2 to 3 by dependabot in https://github.com/Lancetnik/FastDepends/pull/18 * build(deps): bump dawidd6/action-download-artifact from 2.26.0 to 2.28.0 by dependabot in https://github.com/Lancetnik/FastDepends/pull/17 * build(deps): bump pypa/gh-action-pypi-publish from 1.6.4 to 1.8.10 by dependabot in https://github.com/Lancetnik/FastDepends/pull/16 * build(deps): bump actions/checkout from 3 to 4 by dependabot in https://github.com/Lancetnik/FastDepends/pull/15 * chore: remove service from tests CI by Lancetnik in https://github.com/Lancetnik/FastDepends/pull/20 * chore: stable python3.12 by Lancetnik in https://github.com/Lancetnik/FastDepends/pull/21 * chore: change name in CI by Lancetnik in https://github.com/Lancetnik/FastDepends/pull/22 * chore: change PYPI publish trigger by Lancetnik in https://github.com/Lancetnik/FastDepends/pull/23 * build(deps-dev): bump ruff from 0.1.4 to 0.1.5 by dependabot in https://github.com/Lancetnik/FastDepends/pull/25 * build(deps-dev): bump mypy from 1.6.1 to 1.7.0 by dependabot in https://github.com/Lancetnik/FastDepends/pull/24 * fix (26): respect original call locals by Lancetnik in https://github.com/Lancetnik/FastDepends/pull/27
New Contributors * Lancetnik made their first contribution in https://github.com/Lancetnik/FastDepends/pull/14 * dependabot made their first contribution in https://github.com/Lancetnik/FastDepends/pull/18
With this release, async and sync generator function support was added!
This case supports incoming and return types casting both
python from fast_depends import inject
inject def func(a: str) -> int: for _ in range(3) yield a
for i in func(1): assert i == "1"
Also, `inject` has an option to disable **pydantic** validation with `cast=False`. This way `Depends` and your custom fields are still working, but pydantic is not even called.
python from fast_depends import inject
inject(cast=False) def func(a: str) -> int: return a
2.1.0
Now the package is able to validate not only a final decraled fields, but also an `*args, **kwargs` too!