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

Code completion looses Self return type if method is wrapped with type hinted decorator #1919

Open
binste opened this issue Feb 25, 2023 · 1 comment
Labels

Comments

@binste
Copy link

binste commented Feb 25, 2023

The issue came up in this PR in the Altair repo were we are trying to improve autocompletion for IDEs such as VS Code as well as Jupyter with installed JupyterLSP and python-lsp-server. The approach suggested in the PR works for VS Code but not for JupyterLSP. Let me know if this is not a Jedi but a python-lsp-server or jupyterlsp issue.

As a large part of the codebase of Altair is auto-generated, the current approach relies on some type hinted decorators. The actual decorator we use is more complex but I tried to reduce it to a minimal reproducible example below. I'm running this on Python 3.9 with newest Jupyterlab, Jupyterlsp, and python-lsp-server[all]:

from typing import Callable
from typing_extensions import Self

def use_signature(Obj):
    def decorate(f: Callable):
        return f
    return decorate

class SignatureClass:
    def __init__(self, arg1, arg2):
        self.arg1 = arg1

class MainClass:
    @use_signature(SignatureClass)
    def returns_self(self, *args, **kwargs) -> Self:
        return self
    
    def another_method(self):
        pass

return_self correctly shows Self as return type:

image

but it cannot complete `another_method`

image

When removing Callable from the decorate function it still shows Self as return type and can now complete another_method:

image

The expected behaviour would be that another_method can be completed even with the Callable annotation, especially as it still is aware of the return type hint Self.

@davidhalter
Copy link
Owner

Self is currently not supported.

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

No branches or pull requests

2 participants