Giter Site home page Giter Site logo

incant's People

Contributors

hugovk avatar tinche avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

incant's Issues

How to integrate a notion of scopes

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.

UnboundLocalError when reusing dependencies

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.