metapensiero.pj icon indicating copy to clipboard operation
metapensiero.pj copied to clipboard

Update snippets to use enums

Open System25 opened this issue 1 year ago • 2 comments

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.

System25 avatar Oct 28 '23 15:10 System25

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

azazel75 avatar Jan 11 '24 18:01 azazel75

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

System25 avatar Jan 13 '24 09:01 System25