or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/pypi-types-enum34

Type stubs for enum34 - backport of Python 3.4's enum module to earlier Python versions

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/types-enum34@1.1.x

To install, run

npx @tessl/cli install tessl/pypi-types-enum34@1.1.0

index.mddocs/

types-enum34

Type stubs for enum34, a backport of Python 3.4's enum module to earlier Python versions. This package provides comprehensive type annotations for the enum34 library, enabling static type checking with mypy and other type checkers in Python 2.7 codebases.

Package Information

  • Package Name: types-enum34
  • Language: Python (Type Stubs)
  • Installation: pip install types-enum34
  • Target Platform: Python 2.7
  • Purpose: Type annotations for enum34 backport library

Core Imports

import enum

Common imports for specific enum components:

from enum import Enum, IntEnum, Flag, IntFlag, EnumMeta, unique, auto

Basic Usage

from enum import Enum, IntEnum, unique

# Basic enumeration
class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3

# Integer enumeration
class Status(IntEnum):
    INACTIVE = 0
    ACTIVE = 1
    PENDING = 2

# Unique enumeration (prevents duplicate values)
@unique
class Direction(Enum):
    NORTH = 1
    SOUTH = 2
    EAST = 3
    WEST = 4

# Usage
print(Color.RED.name)        # 'RED'
print(Color.RED.value)       # 1
print(Status.ACTIVE == 1)    # True (IntEnum)

Capabilities

Base Enum Class

The fundamental enumeration class that provides the core enum functionality with named constants and member access.

class Enum(metaclass=EnumMeta):
    name: str
    value: Any
    _name_: str
    _value_: Any
    _member_names_: list[str]
    _member_map_: dict[str, Enum]
    _value2member_map_: dict[int, Enum]
    _ignore_: Union[str, list[str]]  # Python 3.7+
    _order_: str
    __order__: str
    
    @classmethod
    def _missing_(cls, value: object) -> Any: ...
    
    @staticmethod
    def _generate_next_value_(name: str, start: int, count: int, last_values: list[Any]) -> Any: ...
    
    def __new__(cls: type[Self], value: object) -> Self: ...
    def __dir__(self) -> list[str]: ...
    def __format__(self, format_spec: str) -> str: ...
    def __hash__(self) -> Any: ...
    def __reduce_ex__(self, proto: object) -> Any: ...

Enum Metaclass

The metaclass that provides enumeration behavior including iteration, membership testing, and member access by name.

class EnumMeta(ABCMeta):
    def __iter__(self: type[_T]) -> Iterator[_T]: ...
    def __reversed__(self: type[_T]) -> Iterator[_T]: ...
    def __contains__(self, member: object) -> bool: ...
    def __getitem__(self: type[_T], name: str) -> _T: ...
    def __len__(self) -> int: ...
    
    @property
    def __members__(self: type[_T]) -> Mapping[str, _T]: ...

Integer Enumeration

Enumeration where members are also integers, providing both enum behavior and integer arithmetic compatibility.

class IntEnum(int, Enum):
    value: int

Flag Enumeration

Enumeration designed for bitwise operations, allowing flag combinations using OR, AND, XOR, and NOT operators.

class Flag(Enum):
    def __contains__(self: _T, other: _T) -> bool: ...
    def __bool__(self) -> bool: ...
    def __or__(self: Self, other: Self) -> Self: ...
    def __and__(self: Self, other: Self) -> Self: ...
    def __xor__(self: Self, other: Self) -> Self: ...
    def __invert__(self: Self) -> Self: ...

Integer Flag Enumeration

Flag enumeration where members are also integers, supporting bitwise operations with both flags and integer values.

class IntFlag(int, Flag):
    def __or__(self: Self, other: Union[int, Self]) -> Self: ...
    def __and__(self: Self, other: Union[int, Self]) -> Self: ...
    def __xor__(self: Self, other: Union[int, Self]) -> Self: ...
    __ror__ = __or__
    __rand__ = __and__
    __rxor__ = __xor__

Auto Value Generation

Sentinel class for automatic value generation in enum definitions.

class auto(IntFlag):
    value: Any

Uniqueness Decorator

Decorator function that ensures all enum values are unique, raising ValueError for duplicate values.

def unique(enumeration: _S) -> _S:
    """
    Decorator that ensures only unique enum values exist.
    
    Parameters:
    - enumeration: Enum class to validate
    
    Returns:
    The same enum class with uniqueness enforced
    
    Raises:
    ValueError: If duplicate values are found
    """

Type Variables

_T = TypeVar("_T")
_S = TypeVar("_S", bound=type[Enum])

Constants

_auto_null: Any  # Internal constant for auto value handling

Usage Examples

Creating Basic Enums

from enum import Enum

class Animal(Enum):
    DOG = 1
    CAT = 2
    BIRD = 3

# Access members
print(Animal.DOG.name)   # 'DOG'
print(Animal.DOG.value)  # 1

# Iteration
for animal in Animal:
    print(f"{animal.name}: {animal.value}")

# Membership testing
print(Animal.DOG in Animal)  # True

Working with IntEnum

from enum import IntEnum

class Priority(IntEnum):
    LOW = 1
    MEDIUM = 2
    HIGH = 3

# IntEnum members are also integers
print(Priority.HIGH == 3)     # True
print(Priority.HIGH > Priority.LOW)  # True
print(Priority.HIGH + 1)      # 4

Flag Operations

from enum import Flag, auto

class Permission(Flag):
    READ = auto()
    WRITE = auto()
    EXECUTE = auto()

# Combine flags
read_write = Permission.READ | Permission.WRITE
all_perms = Permission.READ | Permission.WRITE | Permission.EXECUTE

# Test flags
print(Permission.READ in read_write)      # True
print(Permission.EXECUTE in read_write)   # False

Using unique Decorator

from enum import Enum, unique

@unique
class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3
    # CRIMSON = 1  # Would raise ValueError due to duplicate value

Auto Value Generation

from enum import Enum, auto

class Direction(Enum):
    NORTH = auto()
    SOUTH = auto()
    EAST = auto()
    WEST = auto()

print(Direction.NORTH.value)  # 1
print(Direction.SOUTH.value)  # 2