Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2746])(https://github.com/Pycord-Development/pycord/pull/2746)
- Updated `valid_locales` to support `in` and `es-419`.
([#2767])(https://github.com/Pycord-Development/pycord/pull/2767)
- Fixed `TypeError` when using `Flag` with Python 3.11+.
([#2759])(https://github.com/Pycord-Development/pycord/pull/2759)

### Changed

Expand Down
24 changes: 12 additions & 12 deletions discord/ext/commands/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, Iterator, Literal, Pattern, TypeVar, Union

from discord.utils import MISSING, MissingField, maybe_coroutine, resolve_annotation

if sys.version_info >= (3, 11):
_MISSING = MissingField
else:
_MISSING = MISSING
from discord.utils import (
MISSING,
maybe_coroutine,
missing_field_factory,
resolve_annotation,
)

from .converter import run_converters
from .errors import (
Expand Down Expand Up @@ -86,13 +86,13 @@ class Flag:
Whether multiple given values overrides the previous value.
"""

name: str = _MISSING
name: str = missing_field_factory()
aliases: list[str] = field(default_factory=list)
attribute: str = _MISSING
annotation: Any = _MISSING
default: Any = _MISSING
max_args: int = _MISSING
override: bool = _MISSING
attribute: str = missing_field_factory()
annotation: Any = missing_field_factory()
default: Any = missing_field_factory()
max_args: int = missing_field_factory()
override: bool = missing_field_factory()
cast_to_dict: bool = False

@property
Expand Down
5 changes: 4 additions & 1 deletion discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def __repr__(self) -> str:
# field(default=MISSING) produces the same error, but passing a lambda to
# default_factory produces the same behavior as default=MISSING and does not raise an
# error.
MissingField = field(default_factory=lambda: MISSING)


def missing_field_factory() -> field:
return field(default_factory=lambda: MISSING)


class _cached_property:
Expand Down