Skip to content

Commit bc528f1

Browse files
committed
🐛 Fix dataclasses.field can't be reused
1 parent 1f30a35 commit bc528f1

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

discord/ext/commands/flags.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
from dataclasses import dataclass, field
3232
from typing import TYPE_CHECKING, Any, Iterator, Literal, Pattern, TypeVar, Union
3333

34-
from discord.utils import MISSING, MissingField, maybe_coroutine, resolve_annotation
35-
36-
if sys.version_info >= (3, 11):
37-
_MISSING = MissingField
38-
else:
39-
_MISSING = MISSING
34+
from discord.utils import (
35+
MISSING,
36+
maybe_coroutine,
37+
missing_field_factory,
38+
resolve_annotation,
39+
)
4040

4141
from .converter import run_converters
4242
from .errors import (
@@ -86,13 +86,13 @@ class Flag:
8686
Whether multiple given values overrides the previous value.
8787
"""
8888

89-
name: str = _MISSING
89+
name: str = missing_field_factory()
9090
aliases: list[str] = field(default_factory=list)
91-
attribute: str = _MISSING
92-
annotation: Any = _MISSING
93-
default: Any = _MISSING
94-
max_args: int = _MISSING
95-
override: bool = _MISSING
91+
attribute: str = missing_field_factory()
92+
annotation: Any = missing_field_factory()
93+
default: Any = missing_field_factory()
94+
max_args: int = missing_field_factory()
95+
override: bool = missing_field_factory()
9696
cast_to_dict: bool = False
9797

9898
@property

discord/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ def __repr__(self) -> str:
119119
# field(default=MISSING) produces the same error, but passing a lambda to
120120
# default_factory produces the same behavior as default=MISSING and does not raise an
121121
# error.
122-
MissingField = field(default_factory=lambda: MISSING)
122+
123+
124+
def missing_field_factory() -> field:
125+
return field(default_factory=lambda: MISSING)
123126

124127

125128
class _cached_property:

0 commit comments

Comments
 (0)