Cool, any examples of libraries that use it for dependency injection or FFI or validation?
@inject
def main(service: Service = Provide[Container.service]) -> None:
...
FastAPI also does a similar sort of trick, for DI and also request parsing.https://python-dependency-injector.ets-labs.org/introduction...
taichi does ffi with their own dsl, cython with c.
I you haven't tried pydantic or sister projects (django-ninja, fastapi and typer), this is a good place to start. They bring a breath of fresh air and are quite fun to use.
The dep injection is fastapi and typer code though, and quite tied to it. So it's worth mentioning that somebody is attempting (quite successfully from the look of it) to create a generic lib of dep injection using annotation named DI, inspired by those libs: https://github.com/adriangb/di
An example:
@dataclass
class HackerNewsPost:
title: str
author: str
votes: int = 0
This will generate a constructor that looks like this: def __init__(title: str, author: str, votes: int = 0):
self.title = title
self.author = author
self.votes = votes
This is pretty useful, writing __init__ boilerplate has been a common thing in my experience using Python, and it makes code more compact and readable.It can do some other things too!
https://cython.readthedocs.io/en/latest/src/tutorial/external.html