You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixed Unknown Enum Handling for Future API Additions
Problem
The package would break when a new metric was added to the Wise Old Man API. This creates an exception that would throw if trying to access a route that contained the new metric.
Solution
Implement an error handler that returns Metric.Unknown in the case where the current version doesn't contain said metric, but still return the data. This was achieved by creating a new class called MetaEnum, that I passed into the metaclass param for BaseEnum. Not sure if this is really the right way to do this, or if you want me to change it, but the test class I created passes. I tried to do it via the discussed _missing_ keyword, but I couldn't figure out why that method was never being called.
classMetaEnum(EnumMeta):
def__getitem__(cls: MetaEnum, name: str) ->t.Any:
try:
returnsuper().__getitem__(name)
exceptKeyError:
print(
f"{name!r} is not a valid {cls.__name__} variant. ""Please report this issue on github at https://github.com/Jonxslays/wom.py/issues/new"
)
returncls.Unknown
Fixed Unknown Enum Handling for Future API Additions
Problem
The package would break when a new metric was added to the Wise Old Man API. This creates an exception that would throw if trying to access a route that contained the new metric.
Solution
Implement an error handler that returns
Metric.Unknown
in the case where the current version doesn't contain said metric, but still return the data. This was achieved by creating a new class calledMetaEnum
, that I passed into themetaclass
param forBaseEnum
. Not sure if this is really the right way to do this, or if you want me to change it, but the test class I created passes. I tried to do it via the discussed_missing_
keyword, but I couldn't figure out why that method was never being called.This fix can be found here: #82
The text was updated successfully, but these errors were encountered: