PyDev does not recognize celery decorators

I had the following problem with my Python / Celery project in Eclipse / PyDev. I defined my task function in the myapp.tasks module as follows:

@celery.task(max_retries=None) def mytask(parm1): ... myapp.myfunction(parm1) ... 

Then in another module I want to send a snooze signal to the task that calls the function. So I like this:

 import myapp.tasks ... def myfunction(parm1): ... raise myapp.tasks.mytask.retry(countdown=60) 

For some reason, PyDev marks the last line with the error message: 'Undefined variable from import: retry' But the code does work. Is this a PyDev issue that doesn't recognize decorators, or am I doing something wrong here?

+6
source share
2 answers

Pydev apparently uses static analysis, which is rather strange for a dynamic language. But now I have added a hack that should allow PyDev to successfully statically analyze the celery module. You can try installing branch 3.0:

 pip install https://github.com/celery/celery/zipball/3.0 
0
source

PyDev uses static analysis. You can add "Forced Builtin" to fix the error marker.

  • Go to the window → Settings
  • Choose PyDev -> interpreters -> Python interpreters in the left pane
  • Select the python interpreter you use for celery in the right pane.
  • Below, select "Forced Bultins" and click "Create ..."
  • Add myapp.tasks.mytask or any other required types

In my case, I needed to add "celery.decorators" to resolve a similar error. I am using Eclipse Neon (4.6.3), but the interface has changed a lot. I used this method to fix protocol buffer errors for several years.

0
source

Source: https://habr.com/ru/post/927153/


All Articles