On this page
  1. enum.property
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

enum.property

Prev: enum.pickle_by_global_name | Up: enum | Next: enum.ReprEnum
Rel: enum.auto, enum.Enum, enum.EnumCheck, enum.EnumDict
Ref: docs.python.org — enum.property
Tags: #public #python3 #stdlib #enum


Import

import enum
from enum import property

Signature & Overview

enum.property(fget=None, fset=None, fdel=None, doc=None)

This is a descriptor, used to define attributes that act differently when accessed through an enum member and through an enum class.

Methods & Attributes

Usage

import enum

class Planet(enum.Enum):
    EARTH = (1, "blue")

    @enum.property
    def color(self) -> str:
        return self.value[1]

assert Planet.EARTH.color == "blue"

Gotchas

REPL Inspect

from enum import property
help(property)

Linked from

Related notes