Skip to content

Commit

Permalink
Fix errors that will occur in python3.11 (#1680)
Browse files Browse the repository at this point in the history
Apply correct fix for MISSING default

Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com>
  • Loading branch information
Youtong0826 and BobDotCom committed Oct 14, 2022
1 parent e4aa8e2 commit 9b7f5c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 7 additions & 7 deletions discord/ext/commands/flags.py
Expand Up @@ -31,7 +31,7 @@
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, Iterator, Literal, Pattern, TypeVar, Union

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

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

name: str = MISSING
name: str = MissingField
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 = MissingField
annotation: Any = MissingField
default: Any = MissingField
max_args: int = MissingField
override: bool = MissingField
cast_to_dict: bool = False

@property
Expand Down
6 changes: 6 additions & 0 deletions discord/utils.py
Expand Up @@ -38,6 +38,7 @@
import warnings
from base64 import b64encode
from bisect import bisect_left
from dataclasses import field
from inspect import isawaitable as _isawaitable
from inspect import signature as _signature
from operator import attrgetter
Expand Down Expand Up @@ -114,6 +115,11 @@ def __repr__(self) -> str:


MISSING: Any = _MissingSentinel()
# As of 3.11, directly setting a dataclass field to MISSING causes a ValueError. Using
# 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)


class _cached_property:
Expand Down

0 comments on commit 9b7f5c6

Please sign in to comment.