How to return from enum from property in enum


This Content is from Stack Overflow. Question asked by Christian Pojoni

I have an enum with a set as value for the items. In a property method I would like to return an intersection of the previous chained enum. But the result type of the property should be the same enum class.

Given this abstract example

from enum import Enum

class Letters(Enum):
    abc = {'a', 'b', 'c'}

    def a(self):
        """ Returns a subset of a Letters Enum """
        letter = {'a'}
        return letter.intersection(self.value)

The type of an Item is an enum of Letters, which is correct

# prints <enum 'Letters'>

But when I call the property of the resulting enum, it is of type set

# prints <class 'set'>

How can I change the code so that the property returns a value of type enum?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?