jep icon indicating copy to clipboard operation
jep copied to clipboard

Enums in Python

Open RevolvingMadness opened this issue 1 year ago • 1 comments

Describe the problem When declaring a type hint file, how do you declare an enum? Let me give an example:

Java code:

public enum MyEnum {
 ENUMVALUE1, ENUMVALUE2;
}

Python Type Hint Code:

class MyEnum:
 ENUMVALUE1: object
 ENUMVALUE2: object

Python Code:

from type_hint_file import MyEnum
print(MyEnum.ENUMVALUE1)

I get the error: type object 'MyEnum' has no attribute 'MYENULVALUE1'

Environment (please complete the following information):

  • OS Platform, Distribution, and Version: Windows, Home, 11
  • Python Distribution and Version: Python, 3.11.4
  • Java Distribution and Version: OpenJDK, 17
  • Jep Version: 4.1.1
  • Python packages used (e.g. numpy, pandas, tensorflow): None

RevolvingMadness avatar Jun 22 '23 21:06 RevolvingMadness

This may or may not be irrelevant, but in your error message it has "MYENULVALUE1" not "ENUMVALUE1". So there is the "my" part on one and not the other and then the "enul" vs "enum" part.

I don't understand what you expect to happen. It looks like you're declaring a Java enum/class named MyEnum and then a Python class named MyEnum. Those are two different classes.

ndjensen avatar Jul 11 '23 21:07 ndjensen