-
Notifications
You must be signed in to change notification settings - Fork 768
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
Unable to autosuggest members with typing.Literal types when used in Generic classes #4938
Comments
Thanks for the issue. This looks like a bug to me. We have support for |
Thanks so much for acknowledging. I will use this issue to document other related ones on the same snippet I have posted above. I have found similar issues with other magic methods like My expectation is that, the way Intellisense works for |
Intellisense DOES NOT work for the class GenericType(Generic[T]):
def calculate(self, value: T) -> None:
pass
# Intellisense DOES NOT work
def __getitem__(self, value: T) -> Any:
pass Intellisense WORKS for the below signature of class GenericType(Generic[T]):
def calculate(self, value: T) -> None:
pass
# Intellisense WORKS
def __getitem__(self, value: DS1FieldNames) -> Any:
pass |
… with literal types. The old logic didn't properly handle generics or overloads. This addresses microsoft/pylance-release#4938.
There is currently no support for The completion provider does have support for a Here's how it looks with the new logic in place: |
Thanks Eric. Regarding the On the When it comes to |
The logic works only with a |
Thanks Eric. I will raise a new feature request and I will close this issue. |
Environment
Language Server version: v2023.10.11 (pre-release version)
OS and version: macOS 13.2.1 Ventura
Python version: 3.11.5
Issue
Consider the below snippet.
In the above example, when I invoke the method
c.calculate()
, I get the field suggestion as in the image below.But when I type
c.
, I expected that the literal values should be populated in the list of attributes for the object c. But this wasn't the case.If I change the signature of the
__getattr__
, it works as expected, as you could see in the image below.NOTE - If I invoke the magic methods explicitly, the auto suggestion works.
This applies to the
__getitem__
method too. I assume this is the case for all the dunder methods overridden in the class.I ran pyright against this code and it didn't complain, so I assume it passed the type checking rules. When I used the
reveal_type
for all these magic methods, pyright gave me the correct types.Am I doing something incorrect here? Or currently such autosuggestions are not supported on magic dunder methods implemented using generic types?
I am not sure if this would qualify for a feature request? Getting these members through auto suggestion helps greatly minimizing the member spelling lookups. Currently to make it work, I would need to duplicate the class implementation if I need to get the auto suggestions for different
typing.Literal
values.The text was updated successfully, but these errors were encountered: