Browse Source

[commands] Fix flag annotations not working under 3.14

v2.6.x
Rapptz 2 days ago
parent
commit
91bf014ddf
  1. 8
      discord/ext/commands/flags.py

8
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]: def get_flags(namespace: Dict[str, Any], globals: Dict[str, Any], locals: Dict[str, Any]) -> Dict[str, Flag]:
annotations = namespace.get('__annotations__', {}) 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__'] case_insensitive = namespace['__commands_flag_case_insensitive__']
flags: Dict[str, Flag] = {} flags: Dict[str, Flag] = {}
cache: Dict[str, Any] = {} cache: Dict[str, Any] = {}

Loading…
Cancel
Save