pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Intellisense still not fully working with Enum classes

Open tomhsel opened this issue 2 years ago • 5 comments

I believe this may be related to #1905 and #4734.

Environment data

  • Language Server version: 2023.9.30
  • OS and version: Windows 11 build 22621.2283 and Ubuntu 22.04.3 (WSL)
  • Python version (& distribution if applicable, e.g. Anaconda):
    • 3.8.10, 3.9.13, 3.10.11, 3.11.6 (python.org Windows installers)
    • 3.10.12 (through apt on Ubuntu)

Code Snippet

from enum import Enum

class Test(Enum):
    X = "x"

    @property
    def is_x(self) -> bool:
        return True

Repro Steps

  1. Type Test.X.

Expected behavior

The property is_x should be displayed in the suggestions for Test.X.

Actual behavior

Only attributes that are universally applicable to Enum members are displayed (name, value, and the standard sunder/dunder attributes)

Even worse, if the Enum class doesn't inherit directly from enum.Enum, the suggestions popup is empty (or displays No suggestions. if you try to force the matter with Ctrl+Space). This includes Enums that make use of enum.IntEnum or Python 3.11's enum.ReprEnum and enum.StrEnum.

The example from https://docs.python.org/3/howto/enum.html#planet also fails to produce the attributes created in __init__.

It should also be noted that all of these attributes added in each of these various ways are correctly understood by the typing system when used, they are simply missing from the provided suggestions.

tomhsel avatar Oct 05 '23 23:10 tomhsel

I also noticed this; I am adding all kind of methods to our enums but they don't show up in autocomplete 0_o

ion-elgreco avatar Feb 16 '24 13:02 ion-elgreco

This bug is a side-effect of changes made for https://github.com/microsoft/pylance-release/issues/1905 and https://github.com/microsoft/pylance-release/issues/4734. We're still filtering out too many members on enum instances.

debonte avatar Feb 16 '24 21:02 debonte

Hi @heejaechang any updates on this? I think giving enums custom methods is a pretty great pattern that I encourage folks to do, but the lack of intellisense makes this tough. many thanks :)

fordneild avatar Jun 02 '24 15:06 fordneild

I believe it is already fixed. I think we forgot to mark this as fixed.

image

heejaechang avatar Jun 03 '24 17:06 heejaechang

@heejaechang @fordneild But it is not working. The problem, that the instance of enum must also have this hint telegram-cloud-photo-size-2-5465241967882524802-x

Denis-Alexeev avatar Jun 25 '24 12:06 Denis-Alexeev

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

heejaechang avatar Jul 15 '24 22:07 heejaechang