# enum

Starlark module for working with enums.

An enumeration is a set of symbolic names (members) bound to unique, constant values. Within an enumeration, the members can be compared by identity, and the enumeration itself can be iterated over.

Because Enums are used to represent constants we recommend using UPPER\_CASE names for enum members, and will be using that style in our examples.

## enum.Enum(class\_name, names\_, module=None, qualname=None, type=None, start=1)

Create a new *IMMUTABLE* Enum class.

Example:

```python
enum.Enum('_Languages', [('Java', 0), ('Python', 1), ('Larky', 2)])
```

**Parameters:**

* **class\_name** - Enum name.
* **names** - names can be:
  * A string containing member names, separated either with spaces or commas. Values are incremented by 1 from start.
  * An iterable of member names. Values are incremented by 1 from start.
  * An iterable of (member name, value) pairs.
  * A mapping of member name -> value pairs.

*Returns:* Larky Enum representation.

## enum.enum2(\*sequential, \*\*named)

One of the ways to initialize Enum

Example:

```python
_enum = enum.enum2('_TRY', '_EXCEPT', '_ELSE', '_FINALLY', '_BUILD')
```

**Parameters:**

* **sequential** - a list or tuple that we will use as enum values.
* **named** - name/value mapping.

*Returns:* enum with reversed\_mapping for output formatting.

## enum.enumify\_iterable(iterable, enum\_dict, numerator=None)

A hacky function to turn an iterable into a dict with whose keys are the members of the iterable, and value is the index.

If the key is a tuple, it will iterate over the keys and assign the same enumerated position.

A numerator is a callable that takes the enumerated position and returns the expected number in order. For example, numerator=lambda x: x << 2 will map to 1, 2, 4, 8, 16 instead of 1, 2, 3, 4, 5

```python
__ = -1  # Alias for the invalid class
RegexFlags = _enumify_iterable(iterable=[
...             ("I", "IGNORECASE"),
...             ("S", "DOTALL"),
...             ("M", "MULTILINE"),
...             ("U", "UNICODE"),
...             "LONGEST_MATCH",
...             ("A", "ASCII"),
...             "DEBUG",
...             ("L", "LOCALE"),
...             ("X", "VERBOSE"),
...             ("T", "TEMPLATE"),
... ], enum_dict={'__': __}, numerator=lambda x: 1 << x)
assert RegexFlags["I"] == 1
assert RegexFlags["DOTALL"] == RegexFlags["S"] == 2
assert RegexFlags["MULTILINE"] == RegexFlags["M"] == 4
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.verygoodsecurity.com/vault/developer-tools/larky/library-api/enum.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
