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

No autocomplete for Literal for __getitem__ #1318

Closed
kumaraditya303 opened this issue May 20, 2021 · 7 comments
Closed

No autocomplete for Literal for __getitem__ #1318

kumaraditya303 opened this issue May 20, 2021 · 7 comments
Assignees
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@kumaraditya303
Copy link

Environment data

  • Language Server version: v2021.5.3
  • OS and version: Windows 10 21H1
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.9.5

Expected behaviour

It should show autocomplete for __getitem__

Actual behaviour

No autocomplete for __getitem__

Code Snippet / Additional information

Screenshot (69)

# pyright: strict
from typing import Literal


class Foo:
    def __getitem__(self, key: Literal["chromium", "firefox", "webkit"]) -> int:
        return 1


f = Foo()
k = f[]
@jakebailey
Copy link
Member

@bschnurr is this the bug you had noticed?

@kumaraditya303 If you switch your type checking mode up, do you see the literal completions working? I believe there's a bug there, but it'd be helpful to check.

@kumaraditya303
Copy link
Author

@jakebailey Nope there isn't any autocomplete for literals

@erictraut
Copy link
Contributor

erictraut commented May 20, 2021

This isn't a bug. It's a feature request.

It's technically possible for us to add completion suggestions for the case where a __getitem__ method's key parameter is annotated with a union of literals, but it's a very specialized (and I think rare) case. I've never seen this done before. You may be the first person to do this.

The amount of code to support this is not huge, but it's also not trivial. We could leave this issue open to see if others upvote it.

@jakebailey
Copy link
Member

Yes, I was confusing this with function argument literal completion, which does have a bug at the moment.

@kumaraditya303
Copy link
Author

The pyright correctly identifies the type and also reports error if the value of key in not a matching literal, also if you want to support this then make sure this works for all the functions of the object protocol

@kumaraditya303
Copy link
Author

kumaraditya303 commented May 20, 2021

They are plenty of use cases for this, the common one for __getitem__ being creating a dict like object, a read-only dict with predefined keys etc, but there are many more sophisticated use cases for operator overloading

@judej judej added the enhancement New feature or request label May 20, 2021
@github-actions github-actions bot removed the triage label May 20, 2021
@heejaechang heejaechang self-assigned this Jan 6, 2022
@heejaechang heejaechang added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jan 7, 2022
@bschnurr
Copy link
Member

This issue has been fixed in version 2022.1.1, which we've just released. You can find the changelog here: CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 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

6 participants