Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Can't inject decorated classes, getting pinject.errors.WrongArgTypeError: wrong type for arg cls: expected class but got <decorator> #44

Open
eblis opened this issue Dec 10, 2019 · 2 comments

Comments

@eblis
Copy link

eblis commented Dec 10, 2019

I have a simple class with a no-op decorator defined and I'm trying to use pinject to instantiate it, but haven't got this to work yet.

Python 3.8
pinject==0.14.1

class Controller:
    def __init__(self, original_instance):
        self.original_instance = original_instance

@Controller
class UsersController:
  pass


users = obj_graph.provide(UsersController)

Trying to run this i get the following error:

example_python-3XnK4UKl\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2019.2.3\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 56103 --file Main.py
pydev debugger: process 33564 is connecting

Connected to pydev debugger (build 192.6817.19)
Traceback (most recent call last):
  File "example_python/Main.py", line 29, in <module>
    users = obj_graph.provide(UsersController)
  File "example_python-3XnK4UKl\lib\site-packages\pinject\object_graph.py", line 193, in provide
    support.verify_class_type(cls, 'cls')
  File "example_python-3XnK4UKl\lib\site-packages\pinject\support.py", line 85, in verify_class_type
    _verify_type(inspect.isclass, elt, arg_name, 'class')
  File "example_python-3XnK4UKl\lib\site-packages\pinject\support.py", line 104, in _verify_type
    raise errors.WrongArgTypeError(
pinject.errors.WrongArgTypeError: wrong type for arg cls: expected class but got Controller

Process finished with exit code 1
@MrGreenTea
Copy link

MrGreenTea commented Apr 22, 2020

Well yes, your class is not a class anymore, but an instance of Controller

@loweryjk
Copy link

As @MrGreenTea said, this is not a bug. Can we close this issue please?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants