[commands] Add FlagConverter.__iter__
This commit is contained in:
parent
829c2d4a1a
commit
1c312a158a
@ -40,6 +40,7 @@ from discord.utils import maybe_coroutine
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import (
|
from typing import (
|
||||||
Dict,
|
Dict,
|
||||||
|
Iterator,
|
||||||
Optional,
|
Optional,
|
||||||
Pattern,
|
Pattern,
|
||||||
Set,
|
Set,
|
||||||
@ -443,6 +444,14 @@ class FlagConverter(metaclass=FlagsMeta):
|
|||||||
how this converter works, check the appropriate
|
how this converter works, check the appropriate
|
||||||
:ref:`documentation <ext_commands_flag_converter>`.
|
:ref:`documentation <ext_commands_flag_converter>`.
|
||||||
|
|
||||||
|
.. container:: operations
|
||||||
|
|
||||||
|
.. describe:: iter(x)
|
||||||
|
|
||||||
|
Returns an iterator of ``(flag_name, flag_value)`` pairs. This allows it
|
||||||
|
to be, for example, constructed as a dict or a list of pairs.
|
||||||
|
Note that aliases are not shown.
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@ -468,6 +477,10 @@ class FlagConverter(metaclass=FlagsMeta):
|
|||||||
def _can_be_constructible(cls) -> bool:
|
def _can_be_constructible(cls) -> bool:
|
||||||
return all(not flag.required for flag in cls.__commands_flags__.values())
|
return all(not flag.required for flag in cls.__commands_flags__.values())
|
||||||
|
|
||||||
|
def __iter__(self) -> Iterator[Tuple[str, Any]]:
|
||||||
|
for flag in self.__class__.__commands_flags__.values():
|
||||||
|
yield (flag.name, getattr(self, flag.attribute))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def _construct_default(cls: Type[F], ctx: Context) -> F:
|
async def _construct_default(cls: Type[F], ctx: Context) -> F:
|
||||||
self: F = cls.__new__(cls)
|
self: F = cls.__new__(cls)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user