Intellisense still not fully working with Enum classes
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
- 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.
I also noticed this; I am adding all kind of methods to our enums but they don't show up in autocomplete 0_o
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.
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 :)
I believe it is already fixed. I think we forgot to mark this as fixed.
@heejaechang @fordneild But it is not working. The problem, that the instance of enum must also have this hint
This issue has been fixed in prerelease version 2024.7.100, which we've just released. You can find the changelog here: CHANGELOG.md