Autocomplete in pycharm ray
I rely on auto complete all the time.
Ray(https://github.com/ray-project/ray ) remote functions and actors do not seem to support auto complete.
Has anyone come across that problem?
For example:
import time
import ray
ray.init(num_cpus=4) # Specify this system has 4 CPUs.
@ray.remote
class Counter:
def __init__(self):
self.value = 0
def increment(self, dfdf:int):
self.value += 1
return self.value
def get_counter(self):
return self.value
counter_actor = Counter.remote()
When I now type
counter_actor.
in pycharm, the methods of the counter Class are not available:
https://dl.dropboxusercontent.com/s/sfqhqau6eh6dz00/Screenshot%202021-11-24%20at%2023.44..png?dl=0
when I type
counter_actor.increment.remote()
the argument name dfdf is not being offered and no tool tips are displayed.
How can I remedy this situation?
Please sign in to leave a comment.
Hello,
This is not specific for the ray package.
The this is that code completion in the PyCharm editor does not run any code and uses static analysis only. Because of that, there will always be cases when you get completion in the Python console but not in the editor, and those are not bugs in PyCharm. PyCharm is not aware of ``
Please let me know if that answers your question.
Thanks.
I am aware that runtime command completion is different from programmatic command completion.
My question was not about that.
When I use other packages, the command completion in pycharm in the editor works.
Pycharm knows the Class or function declaration and offers correct command completion, including function parameter information and completion.
Only for Ray, for specific cases as outlined in my question, this seems not to be the case.
All other packages just work fine.
How can I remedy that situation?
Could you please share another code example then?
Thank you for your cooperation!
What do you mean by "other code examples"?
I apologize for the misunderstanding. You mentioned the code completion does not work at all for the ray package. Could you please provide me with a code example where you would expect completion to be?
>Only for Ray, for specific cases as outlined in my question, this seems not to be the case.
This specific case refers to the static analysis, which prevents code completion appearance.
OK, I am confused about the difference between static and runtime.
It seems to me that you are saying that code completion in my specific context is classified as runtime, and not static.
It seems to me that because of that classification you do not expect code completion to work in my specific context.
Is that true?
If that is true, how I would be able to use Ray in the way proposed in any Ray tutorial and still be able to have code completion in pycharm?
You seem to be saying, that if that is true, then any and all code mentioned in any and all Ray tutorials would need runtime code completion for any editor to have actual code completion?
Does that mean that all people who use Ray actually have no code completion while they are programming, because having code completion during programming necessitates static code completion?
I am confused because there does not seem to be anything to stop static code analysis to pick up any and all code completion elements that would be present without the decorators used by Ray.
>Is that true?
It is, yes.
>how I would be able to use Ray in the way proposed in any Ray tutorial and still be able to have code completion in pycharm?
It is not possible in PyCharm editor. Python console will provide the completion, but I cannot advise it as a decent alternative.
You are welcome to vote for the corresponding feature requests:
Thanks Antonina.
I believe that porting Python console command completion to the editor is complete overkill for this case.
The ray decorators take the exact same arguments as the corresponding function, method or __init__.
The beginning of a workaround is for example:
counter_actor: Counter
Doing so allows to do:
And have all the available methods in tab completion.
However, we need to write something like
counter_actor.increment.remote(dfdf=12)
and not something like
counter_actor.increment(dfdf=12)
The proposed beginning of a workaround allows to write the latter with proper code completion, but not the former which we need to write.