Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems raised about missing argument when calling a function decorated by celery.shared_task #39

Closed
remihuguet opened this issue Jul 3, 2020 · 4 comments
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@remihuguet
Copy link

Environment data

  • Language Server version: 2020.6.1
  • OS and version: Ubuntu 20.04
  • Python version 3.7.7, virtual env with requirements joined
    requirements_pypi.txt

Expected behaviour

When calling a task defined with celery.app.shared_task decorator, and naming argument, Pylance raises a problem "Argument missing parameter for 'fun'. See code snippet.

problems

Actual behaviour

No problems should be raised.

Logs

[FG] parsing: tests.py (10ms)
[FG] binding: tests.py (2ms)
[BG] analyzing: tests.py ...
[BG]   parsing: tests.py (7ms)
[BG]   binding: tests.py (1ms)
[BG]   checking: tests.py (16ms)
[BG] analyzing: tests.py (25ms)
[FG] parsing: tests.py (5ms)
[FG] binding: tests.py (2ms)
[BG] analyzing: tests.py ...
[BG]   parsing: tests.py (1ms)
[BG]   binding: tests.py (0ms)
[BG]   checking: tests.py (29ms)
[BG] analyzing: tests.py (30ms)

Code Snippet / Additional information

from celery.app import shared_task

@shared_task
def function_one(argument):
    return []

def function_two():
    return function_one(argument=2)
@erictraut
Copy link
Contributor

erictraut commented Jul 3, 2020

Pylance requires type stubs to do the best job possible with type analysis. In this case, I'm presuming that you don't have a type stub available for celery, so it is doing its best to infer types from the library implementation based on the return type(s) of shared_task. In this particular case, shared_task returns two different types, and the type checker can't tell which one is returned for this particular call site. Both types are functions, but one of them is a function that requires a parameter called fun, hence the error.

The best workaround in this case is to find (or create) a type stub for the celery package. A type stub will provide the proper annotations so the type checker can perform analysis correctly in this case without emitting an error.

If you can't find a type stub and don't want to create one, you can suppress this error using "# type: ignore".

@erictraut
Copy link
Contributor

erictraut commented Jul 7, 2020

I've updated the "missing argument" diagnostic to be off by default when typeCheckingMode is "off". Assuming that you haven't set typeCheckingMode to "basic" or "strict", this diagnostic will be suppressed. This change will be in the next version of Pylance.

@erictraut erictraut added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jul 7, 2020
@remihuguet
Copy link
Author

ok thanks you very much for your feedback. I'll try to add so type stub for celery 👍

By the way, this is a great extension, very nice work 👏

@jakebailey
Copy link
Member

This issue has been fixed in version 2020.7.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202070-9-july-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants