-
Notifications
You must be signed in to change notification settings - Fork 85
Open
Description
Hi, first of all I would like to thank you for your work.
As for my question, I use inject in my python flask project. There is no problem when working with python, but when I compile with cython, I get the error “init() takes exactly 2 positional arguments (1 given)”. the reason for this error is that inject cannot do its job
inject.py is
import importlib
import inspect
import pkgutil
from flask_injector import FlaskInjector
from injector import Binder, singleton
from src.resources.base_resource import BaseResource
def injects_config(app):
def configure(binder: Binder):
package = importlib.import_module("src.resources")
for _, module_name, _ in pkgutil.walk_packages(package.__path__, package.__name__ + "."):
module = importlib.import_module(module_name)
for name, obj in inspect.getmembers(module):
if inspect.isclass(obj) and issubclass(obj, BaseResource) and obj is not BaseResource:
print(f"Binding {obj} in module {module_name}")
binder.bind(obj, to=obj, scope=singleton)
FlaskInjector(app=app, modules=[configure])
and using like this:
from injector import inject
class XResource(BaseResource):
def __init__(self, x_service: XService):
super().__init__()
self.x_service = x_service
the code works fine in python but when I compile with cython I get the error “init() takes exactly 2 positional arguments (1 given)””
I don't get this error if I remove inject and derive objects manually, like this:
class XResource(BaseResource):
def __init__(self):
super().__init__()
self.x_service = XService()
the library versions I use are as follows
Flask==2.2.5
Flask-Injector==0.14.0
injector==0.20.1
I am waiting for the help of those who have experience with the problem. Thank you very much.
Metadata
Metadata
Assignees
Labels
No labels