Vyper theorytheory 0/50 · 0%
Types · easy

16. Enums / flags

Named states, and Vyper's bitflag-based flag type.

Modern Vyper (0.3.10+) provides `flag` for named bit-flag states, which behaves much like Solidity's `enum` for simple state machines, but the underlying representation is a bitmask so members can also be combined.

flag Status:
    PENDING
    ACTIVE
    CLOSED

status: public(Status)

@external
def activate():
    self.status = Status.ACTIVE

Because it's a bitmask, `flag` values can be combined with bitwise operators when you need to represent multiple simultaneous states, which a plain enum cannot do.

Check your understanding

  1. 1. What keyword provides enum-like named states in modern Vyper?

  2. 2. Why is `flag` more powerful than a plain enum?

  3. 3. How do you assign a flag member?