| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -206,6 +206,12 @@ def __new__(metacls, cls, bases, classdict): | |||
| 206 | 206 | enum_class.__new__ = Enum.__new__ | |
| 207 | 207 | return enum_class | |
| 208 | 208 | ||
| 209 | + def __bool__(self): | ||
| 210 | + """ | ||
| 211 | + classes/types should always be True. | ||
| 212 | + """ | ||
| 213 | + return True | ||
| 214 | + | ||
| 209 | 215 | def __call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1): | |
| 210 | 216 | """Either returns an existing member, or creates a new enum class. | |
| 211 | 217 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -253,6 +253,19 @@ def spam(cls): | |||
| 253 | 253 | with self.assertRaises(AttributeError): | |
| 254 | 254 | del Season.SPRING.name | |
| 255 | 255 | ||
| 256 | + def test_bool_of_class(self): | ||
| 257 | + class Empty(Enum): | ||
| 258 | + pass | ||
| 259 | + self.assertTrue(bool(Empty)) | ||
| 260 | + | ||
| 261 | + def test_bool_of_member(self): | ||
| 262 | + class Count(Enum): | ||
| 263 | + zero = 0 | ||
| 264 | + one = 1 | ||
| 265 | + two = 2 | ||
| 266 | + for member in Count: | ||
| 267 | + self.assertTrue(bool(member)) | ||
| 268 | + | ||
| 256 | 269 | def test_invalid_names(self): | |
| 257 | 270 | with self.assertRaises(ValueError): | |
| 258 | 271 | class Wrong(Enum): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments