File tree Expand file tree Collapse file tree 2 files changed +12
-17
lines changed Expand file tree Collapse file tree 2 files changed +12
-17
lines changed Original file line number Diff line number Diff line change @@ -57,8 +57,8 @@ def test_at_random(choice: mock.MagicMock) -> None:
57
57
58
58
def test_base_enum_missing () -> None :
59
59
"""A test for the BaseEnum.__missing__ method."""
60
- assert wom .Metric [ "new_fake_metric" ] == wom .Metric .Unknown
61
- assert wom .Metric [ "another_fake_metric" ] == wom .Metric .Unknown
60
+ assert wom .Metric ( "new_fake_metric" ) == wom .Metric .Unknown
61
+ assert wom .Metric ( "another_fake_metric" ) == wom .Metric .Unknown
62
62
assert wom .Metric .Unknown .value == "unknown"
63
63
assert wom .Metric .Unknown != wom .Metric .Vardorvis
64
64
assert wom .Metric .Attack .value == "attack"
Original file line number Diff line number Diff line change 27
27
import sys
28
28
import typing as t
29
29
from enum import Enum
30
- from enum import EnumMeta
31
30
32
31
T = t .TypeVar ("T" , bound = "BaseEnum" )
33
32
42
41
)
43
42
44
43
45
- class MetaEnum (EnumMeta ):
46
- def __getitem__ (cls : MetaEnum , name : str ) -> t .Any :
47
- try :
48
- return super ().__getitem__ (name )
49
- except KeyError :
50
- print (
51
- f"{ name !r} is not a valid { cls .__name__ } variant. "
52
- "Please report this issue on github at https://github.com/Jonxslays/wom.py/issues/new" ,
53
- file = sys .stderr ,
54
- )
55
- return cls .__getitem__ ("Unknown" )
56
-
57
-
58
- class BaseEnum (Enum , metaclass = MetaEnum ):
44
+ class BaseEnum (Enum ):
59
45
"""The base enum all library enums inherit from."""
60
46
61
47
def __str__ (self ) -> str :
@@ -82,6 +68,15 @@ def at_random(cls: t.Type[T]) -> T:
82
68
"""
83
69
return random .choice (tuple (cls ))
84
70
71
+ @classmethod
72
+ def _missing_ (cls : t .Type [T ], value : object ) -> t .Optional [T ]:
73
+ print (
74
+ f"{ value !r} is not a valid { cls .__name__ } variant. "
75
+ "Please report this issue on github at https://github.com/Jonxslays/wom.py/issues/new" ,
76
+ file = sys .stderr ,
77
+ )
78
+ return cls .__getitem__ ("Unknown" )
79
+
85
80
86
81
class Period (BaseEnum ):
87
82
"""A period of time used by the API."""
You can’t perform that action at this time.
0 commit comments