Skip to content

autocomplete from wrong type. #651

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

Open
kaddkaka opened this issue May 28, 2025 · 0 comments
Open

autocomplete from wrong type. #651

kaddkaka opened this issue May 28, 2025 · 0 comments

Comments

@kaddkaka
Copy link

class A:
    pass


class HasAnA:
    def __init__(self, a):
        self._a = a

    def get_a(self):
        return self._a


class Thing:
    def __init__(self, item: A | HasAnA):
        self._item: A
        if isinstance(item, A):
            self._item = item
        else:
            self._item = item.get_a()
        assert isinstance(item, HasAnA)

    def method(self):
        # self._item.  --> tab completes into:
        self._item.get_a()

When the member self._item is declared and assigned as above, pylsp seems to be confused about the type (Can I verify this somehow?)

When I try to tab complete after self._item. (see above) pylsp suggests the method get_a, which is not available on an instance of A.

I tried to clarify and change some types in the example, but the behavior stayed. Is there some other way to rewrite the inside of class Thing so that pylsp unserstands the type correctly?

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

No branches or pull requests

1 participant