Skip to content

Comments

Update snippets to use enums#79

Open
System25 wants to merge 1 commit intometapensiero:masterfrom
System25:feat/allow_enums
Open

Update snippets to use enums#79
System25 wants to merge 1 commit intometapensiero:masterfrom
System25:feat/allow_enums

Conversation

@System25
Copy link

When a class extends enum.Enum you have to define the properties at class level. Also the values need to be an object with "name" and "value" properties.

@azazel75
Copy link
Collaborator

mmm.. Does JS supports Enums? Do you have a link to some docs?

@System25
Copy link
Author

Hi @azazel75, It is not a matter of having enums in Javascript, it is a matter of supporting Python Enums (https://docs.python.org/3/howto/enum.html).

So I have an Enum in Python like:

from enum import Enum
class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3

It has to be transformed into something that allows me to use Color.RED in code.
So "RED" has to be defined at class level.

The code is transformed into:

class Color extends Enum {
}
_pj.set_properties(Color, {"RED": 1, "GREEN": 2, "BLUE": 3});

So _pj.set_properties has to be aware that this is an enum so "RED", "GREEN" and "BLUE" are defined at class level.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants