[commands] Allow Greedy to potentially maintain state between calls

This commit is contained in:
Rapptz
2022-09-20 23:53:48 -04:00
parent 686071814b
commit c35ff4cfc6
2 changed files with 14 additions and 3 deletions

View File

@ -1039,6 +1039,17 @@ class Greedy(List[T]):
return cls(converter=converter)
@property
def constructed_converter(self) -> Any:
# Only construct a converter once in order to maintain state between convert calls
if (
inspect.isclass(self.converter)
and issubclass(self.converter, Converter)
and not inspect.ismethod(self.converter.convert)
):
return self.converter()
return self.converter
if TYPE_CHECKING:
from typing_extensions import Annotated as Range