tinche / incant Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://incant.threeofwands.com
License: Apache License 2.0
Home Page: https://incant.threeofwands.com
License: Apache License 2.0
I'm looking at this project and I like the relative simplicity of it compared to a lot of DI libs for python. But I'm wracking my head trying to figure out how I'd introduce dependency scope. That is...caching what was returned for a factory through multiple invocations on the same incantor object.
To me, this would be necessary to use incantor to inject longer-lived things like a database connection or a requests session or something like that.
Any plans or ideas on this? I'd be interested in helping if I could get an angle on how this might work.
Incant fails when the invoked function uses a dependency, that is already used by another dependency:
import incant
incanter = incant.Incanter()
@incanter.register_by_name
def x() -> int:
return 1
@incanter.register_by_name
def y(x: int) -> int:
return x + 1
def func(x: int, y: int) -> None:
assert x + 1 == y
incanter.invoke(func)
Traceback (most recent call last):
File "/home/stefan/.../lib/tasks.py", line 28, in <module>
incanter.invoke(func)
File "/home/stefan/emsconda/lib/python3.10/site-packages/incant/__init__.py", line 112, in invoke
return self.prepare(fn, is_async=False)(*args, **kwargs)
File "<incant generated invoke of func>", line 2, in invoke_func
UnboundLocalError: local variable '_incant_local_1' referenced before assignment
It does not matter whether I use register_by_name
or register_by_type
.
Python is 3.10, incant is 22.1.0.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.