Skip to content

Commit 6602b5c

Browse files
committed
Rework the value cls creation by defining a NamedTuple as a subclass of typing.NamedTuple.
1 parent de833c3 commit 6602b5c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

fortnite_api/enums.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
from __future__ import annotations
2727

2828
import types
29-
from collections import namedtuple
30-
from typing import TYPE_CHECKING, Any, ClassVar, Dict, Iterator, List, Mapping, Tuple, Type, TypeVar
29+
from typing import TYPE_CHECKING, Any, ClassVar, Dict, Iterator, List, Mapping, NamedTuple, Tuple, Type, TypeVar
3130

3231
from typing_extensions import Self
3332

@@ -52,10 +51,15 @@
5251
OldValue = NewValue = Any
5352

5453

55-
def _create_value_cls(name: str, comparable: bool):
54+
def _create_value_cls(name: str, comparable: bool) -> Type[NamedTuple]:
5655
# Pyright cannot statically recognize the runtime type creation. All of the following
5756
# type ignores in this function are a result of this.
58-
cls = namedtuple('_EnumValue_' + name, 'name value')
57+
class _EnumValue(NamedTuple):
58+
name: str
59+
value: Any
60+
61+
cls = _EnumValue
62+
cls.__name__ = '_EnumValue_' + name
5963
cls.__repr__ = lambda self: f'<{name}.{self.name}: {self.value!r}>' # type: ignore
6064
cls.__str__ = lambda self: f'{name}.{self.name}' # type: ignore
6165
if comparable:

0 commit comments

Comments
 (0)