| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5589bd1 commit 2131a4a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -225,16 +225,6 @@ def __contains__(cls, member): | |||
| 225 | 225 | def __dir__(self): | |
| 226 | 226 | return ['__class__', '__doc__', '__members__'] + self._member_names_ | |
| 227 | 227 | ||
| 228 | - @property | ||
| 229 | - def __members__(cls): | ||
| 230 | - """Returns a mapping of member name->value. | ||
| 231 | - | ||
| 232 | - This mapping lists all enum members, including aliases. Note that this | ||
| 233 | - is a read-only view of the internal mapping. | ||
| 234 | - | ||
| 235 | - """ | ||
| 236 | - return MappingProxyType(cls._member_map_) | ||
| 237 | - | ||
| 238 | 228 | def __getattr__(cls, name): | |
| 239 | 229 | """Return the enum member matching `name` | |
| 240 | 230 | ||
@@ -260,9 +250,22 @@ def __iter__(cls): | |||
| 260 | 250 | def __len__(cls): | |
| 261 | 251 | return len(cls._member_names_) | |
| 262 | 252 | ||
| 253 | + @property | ||
| 254 | + def __members__(cls): | ||
| 255 | + """Returns a mapping of member name->value. | ||
| 256 | + | ||
| 257 | + This mapping lists all enum members, including aliases. Note that this | ||
| 258 | + is a read-only view of the internal mapping. | ||
| 259 | + | ||
| 260 | + """ | ||
| 261 | + return MappingProxyType(cls._member_map_) | ||
| 262 | + | ||
| 263 | 263 | def __repr__(cls): | |
| 264 | 264 | return "<enum %r>" % cls.__name__ | |
| 265 | 265 | ||
| 266 | + def __reversed__(cls): | ||
| 267 | + return (cls._member_map_[name] for name in reversed(cls._member_names_)) | ||
| 268 | + | ||
| 266 | 269 | def __setattr__(cls, name, value): | |
| 267 | 270 | """Block attempts to reassign Enum members. | |
| 268 | 271 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -477,6 +477,13 @@ class Season(Enum): | |||
| 477 | 477 | [Season.SUMMER, Season.WINTER, Season.AUTUMN, Season.SPRING], | |
| 478 | 478 | ) | |
| 479 | 479 | ||
| 480 | + def test_reversed_iteration_order(self): | ||
| 481 | + self.assertEqual( | ||
| 482 | + list(reversed(self.Season)), | ||
| 483 | + [self.Season.WINTER, self.Season.AUTUMN, self.Season.SUMMER, | ||
| 484 | + self.Season.SPRING] | ||
| 485 | + ) | ||
| 486 | + | ||
| 480 | 487 | def test_programatic_function_string(self): | |
| 481 | 488 | SummerMonth = Enum('SummerMonth', 'june july august') | |
| 482 | 489 | lst = list(SummerMonth) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments