Skip to content

fix: 🐛 Fix ValueError when using Flag #2759

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -103,6 +103,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2739](https://github.com/Pycord-Development/pycord/pull/2739))
- Fixed missing `None` type hints in `Select.__init__`.
([#2746])(https://github.com/Pycord-Development/pycord/pull/2746)
- 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