Skip to content

Commit

Permalink
Support Python3.11 Breaking Change
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
kamoo1 committed Sep 3, 2023
1 parent 8362203 commit e20b58d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
20 changes: 20 additions & 0 deletions ah/models/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from typing import ClassVar, Generic, Iterator, TypeVar, Callable, Type, Any
from logging import getLogger, Logger

Expand All @@ -8,6 +9,8 @@
"_RootListMixin",
"_RootDictMixin",
"ConverterWrapper",
"StrEnum_",
"IntEnum_",
)

_VT = TypeVar("_VT")
Expand All @@ -17,6 +20,23 @@
_ITEM_T = TypeVar("_ITEM_T")


# if python 3.11+, use `enum.StrEnum` instead of `str, enum.Enum`
# https://github.com/python/cpython/issues/100458
if sys.version_info >= (3, 11):
from enum import StrEnum as StrEnum_, IntEnum as IntEnum_

else:
from enum import Enum

# Note: must not use `type`
# https://stackoverflow.com/questions/69328274
class StrEnum_(str, Enum):
pass

class IntEnum_(int, Enum):
pass


class ConverterWrapper:
@staticmethod
def optional(converter: Callable) -> Callable:
Expand Down
15 changes: 7 additions & 8 deletions ah/models/blizzard.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import annotations
import os
import abc
import time
from enum import Enum
from typing import (
List,
Iterator,
Expand All @@ -17,11 +15,12 @@

from pydantic import Field, root_validator

from ah.models.base import _BaseModel
from ah.models.base import _BaseModel, StrEnum_

if TYPE_CHECKING:
from ah.api import BNAPI


__all__ = (
"FactionEnum",
"RegionEnum",
Expand All @@ -41,7 +40,7 @@
)


class FactionEnum(str, Enum):
class FactionEnum(StrEnum_):
ALLIANCE = "a"
HORDE = "h"

Expand All @@ -54,19 +53,19 @@ def get_full_name(self) -> str:
raise ValueError(f"Invalid faction: {self}")


class RegionEnum(str, Enum):
class RegionEnum(StrEnum_):
US = "us"
EU = "eu"
KR = "kr"
TW = "tw"


class NameSpaceCategoriesEnum(str, Enum):
class NameSpaceCategoriesEnum(StrEnum_):
DYNAMIC = "dynamic"
STATIC = "static"


class GameVersionEnum(str, Enum):
class GameVersionEnum(StrEnum_):
CLASSIC = "classic1x"
CLASSIC_WLK = "classic"
RETAIL = ""
Expand Down Expand Up @@ -134,7 +133,7 @@ class Config(_BaseModel.Config):
frozen = True


class TimeLeft(str, Enum):
class TimeLeft(StrEnum_):
VERY_LONG = "VERY_LONG"
LONG = "LONG"
MEDIUM = "MEDIUM"
Expand Down
11 changes: 6 additions & 5 deletions ah/models/self.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from functools import partial
from enum import Enum
from heapq import heappush, heappop
from collections import defaultdict
from logging import Logger, getLogger
Expand Down Expand Up @@ -30,6 +29,8 @@
_RootDictMixin,
_RootListMixin,
ConverterWrapper as CW,
StrEnum_,
IntEnum_,
)
from ah.models.blizzard import (
Namespace,
Expand Down Expand Up @@ -79,13 +80,13 @@
"""


class DBTypeEnum(str, Enum):
class DBTypeEnum(StrEnum_):
AUCTIONS = "auctions"
COMMODITIES = "commodities"
META = "meta"


class DBExtEnum(str, Enum):
class DBExtEnum(StrEnum_):
GZ = "gz"
BIN = "bin"
JSON = "json"
Expand Down Expand Up @@ -467,12 +468,12 @@ def get_weighted_market_value(self, ts_now: int) -> int:
return 0


class ItemStringTypeEnum(str, Enum):
class ItemStringTypeEnum(StrEnum_):
PET = "p"
ITEM = "i"


class ILVL_MODIFIERS_TYPES(int, Enum):
class ILVL_MODIFIERS_TYPES(IntEnum_):
ABS_ILVL = -1
REL_ILVL = -2

Expand Down

0 comments on commit e20b58d

Please sign in to comment.