disnake
disnake copied to clipboard
fix(converter): allow Greedy[...] to accept union types
Summary
Fix #1421 => commands.Greedy[...] to correctly support Python 3.10+ union types (PEP 604 A | B) and typing.Union.
Previously, passing a union type like commands.Greedy[disnake.Member | disnake.Object] would raise:
TypeError: Greedy[...] expects a type or a Converter instance
This PR updates Greedy.__class_getitem__ to:
- Detect union types using
typing.get_originandtyping.get_args - Allow union types as valid converters
- Preserve existing restrictions:
Greedy[str]andGreedy[None];Greedy[Optional[T]];Greedy[Greedy[T]] - Use
getattr(converter, "__name__", repr(converter))for safe error messages
Now, Greedy[disnake.Member | disnake.Object] works as expected, allowing commands to greedily consume multiple valid converter types.
Checklist
- [x] If code changes were made, then they have been tested
- [ ] I have updated the documentation to reflect the changes
- [x] I have formatted the code properly by running
uv run nox -s lint - [x] I have type-checked the code by running
uv run nox -s pyright
- [x] This PR fixes an issue
- [ ] This PR adds something new (e.g. new method or parameters)
- [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed)
- [ ] This PR is not a code change (e.g. documentation, README, ...)