I am trying to create an Enum class using the functional API and wanted to have autocompletion once I call the enum class. However vscode does not seem to work if the Enum is created using a temp variable for the elements. Using python 3.10.12 and VSCode: 1.81.1 6c3e3dba23e8fadc360aed75ce363ba185c49794 x64
from enum import Enum
class Color(str, Enum):
AMARILLO = "yellow"
ColorFunctional = Enum("ColorFunctional", {"RED": "red", "BLUE": "blue", "AMARILLO": "yellow"}, type=str)
my_dict = {"RED": "red", "BLUE": "blue", "AMARILLO": "yellow"}
ColorFunctionalIndirect = Enum("B", my_dict, type=str)
assert Color.AMARILLO == "yellow" # -> This autocompletes and higlights!
assert ColorFunctional.AMARILLO == "yellow" # This just autocompletes (no highligthing)
assert ColorFunctionalIndirect.AMARILLO == "yellow" # This neither autocompletes nor highlights
I would expect to at least have the same autocompletion behaviour of ColorFunctional
in ColorFunctionalIndirect
even if the highlighting does not work.
GitHub once replied:
pylance is a static analyzer, so unfortunately none of the dynamic behavior will be supported.
Explanation in vscode official documentation:
Pylance is based on Microsoft’s Pyright static type checking tool, leveraging type stubs (
.pyi
files) and lazy type inferencing to provide a highly-performant development experience.