Metaclass support for method annotations

Answered

Hi,

 

I've run into a limitation of pycharm that i would like to bypass...

I've created a decorator for class that will automatically instantiate the class when accessing one of it's method.

Basically my problem is described by the following screenshot.

as you can see the method add_controller_to_monitor is not a function but a bound method so that it don't require self to be able to run. But at the same time pycharm still ask for the first parameter self when it is not needed.

I've understood from this post https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000665110-auto-completion-for-dynamic-module-attributes-in-python that I won't be able to do it just by doing some code in my project.

the solution for the pyi file might work but as it is a really generic decorator and it is quite boring to write a pyi file every time i use the decorator.

I've think of a plugin but I'm not sure it might do the trick as well ...

is there any way of doing it or should i resign myself with those warning?

1 comment
Comment actions Permalink

Hi, I believe pyi is the simplest solution. The plugin is theoretically possible, but it will require a lot of work and Java/Kotlin knowledge, so it sounds like overkill to me. Feel free to report the problem to PyCharm bug tracker https://youtrack.jetbrains.com/issues/PY with a code sample, perhaps the dev team can handle the issue itself.

0

Please sign in to leave a comment.