Andy
Andy

Reputation: 237

Python 2.7 Backport: enum classes are not instances of abstact enum classes

I am working in the pypi enum34 backport of the Enum class for Python 2.7.

Consider the following:

from enum import *

class ArtTools(Enum):
    pass

class Paintbrushes(ArtTools):
    four_inch_brush = 1
    two_inch_brush = 2
    fan_brush = 3
    paint_knife = 4

print type(Paintbrushes.fan_brush) # <enum 'Paintbrushes'>
assert isinstance(Paintbrushes.fan_brush, ArtTools)  # True/No Error

print type(Paintbrushes) # <class 'enum.EnumMeta'>
assert isinstance(Paintbrushes, ArtTools) # AssertionError

Is there a reason Paintbrushes are not ArtTools? This seems like a bug.

Upvotes: 2

Views: 370

Answers (1)

Jon Deaton
Jon Deaton

Reputation: 4379

Paintbrushes is class, not an instance, therefore it won't be an instance of ArtTools or any other class.

Upvotes: 3

Related Questions