Nested Enum with class and member values

Consider my enum:

class Videos(IntEnum): # 1
    CATS = 11
    DOGS = 12

class Pictures(IntEnum):  # 2
    CATS = 21
    DOGS = 22

class Category:
    VIDEOS = Videos
    PICTURES = Pictures

The API I’m dealing with lets me query just the parent category that includes all it’s children filter=1 (all videos) or specifically get a single child by specifying filter=11 (Cat videos)

How do i represent this in my Enum? Possibly somthing like Category.VIDEOS being 1 while also allowing Category.VIDEOS.CATS being 11?

I could just define another member called ALL i guess?

class Videos(IntEnum): # 1
    ALL = 1
    CATS = 11
    DOGS = 12

Yes, another member called ALL is required, if you want that as one of the possibilities in the enum.

This could be more elegant, but is dry, avoids Enum Subclass Hell, and is a nice application of the Functional API:

from enum import IntEnum

class Videos(IntEnum): 
    CATS = 11
    DOGS = 12

API_Options=IntEnum('API_Options',
                    [(e.name, e.value) for e in Videos] + [('ALL', 1)]
                   )
1 Like