From 91bf014ddfa5f0ddf89a57ee93c23b2106de9d2d Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 14 Oct 2025 17:16:25 -0400 Subject: [PATCH] [commands] Fix flag annotations not working under 3.14 --- discord/ext/commands/flags.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/discord/ext/commands/flags.py b/discord/ext/commands/flags.py index 0b03b81d4..09d925232 100644 --- a/discord/ext/commands/flags.py +++ b/discord/ext/commands/flags.py @@ -178,6 +178,14 @@ def validate_flag_name(name: str, forbidden: Set[str]) -> None: def get_flags(namespace: Dict[str, Any], globals: Dict[str, Any], locals: Dict[str, Any]) -> Dict[str, Flag]: annotations = namespace.get('__annotations__', {}) + if '__annotate__' in namespace: + # In Python 3.14, classes no longer get `__annotations__` and instead a function + # under __annotate__ is used instead that that takes a format argument on how to + # receive those annotations. + # Format 1 is full value, Format 3 is value and ForwardRef for undefined ones + # So format 3 is the one we're typically used to + annotations = namespace['__annotate__'](3) + case_insensitive = namespace['__commands_flag_case_insensitive__'] flags: Dict[str, Flag] = {} cache: Dict[str, Any] = {}