Reputation: 455
I'm using the class enum.Enum in order to restrict the optional fields available to user.
The code used for creating an enum with the following members: Yes, No, Maybe is:
from enum import Enum
my_enum = Enum('my_enum', 'Yes No Maybe')
When using PyCharm, i would like the user to able to see the available members when using my_enum (Yes, No, Maybe):
test = my_enum.Yes
Instead, When pressing the dot, I see the following:
I don't see the optional fields amongst the options.
Upvotes: 1
Views: 183
Reputation: 69081
The problem you experienced is due to Enum members being ephemeral -- which is a fancy way to say they didn't actually exist as class attributes.*
However, a performance enhancement was made (definitely for Python 3.6, possibly also in Python 3.5) that does store the members in the class when possible (which is most of the time).
In other words, it should work soon.
* For the curious, the members were found and returned by the class-level __getattr__
, which is called as a last ditch effort to find attributes after all other methods have failed; the performance enhancement was to go ahead and store the members on the class so they would be found sooner.
Upvotes: 1