Client support for enum? workarounds?

hi @daniel1 and welcome to the forum

I’d definitely turn this into a feature request. No one has yet requested the Enum module (that i’m aware of).

linked topic: Client side Python and skulpt

I’ve looked at the code for Enum - and you can’t shim it straight from cpython i’m afraid. It relies on metaclasses which are not (yet) supported in anvil/skulpt.

Enum has a lot of functionality involved and I would consider writing a custom class that implements just the parts of Enum that you need. Of course how easy depends on how much of the functionality you need.

If it’s simple functionality then consider namedtuple.

from collections import namedtuple
>>> Color = namedtuple('Color', 'RED, GREEN, BLUE', defaults=[3, 4, 5])
>>> C = Color()
>>> C.RED
3

(You can also subclass from namedtuple which might help to extend the behaviour)

1 Like