Skip to content

Conversation

@devbutlazy
Copy link

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_origin and typing.get_args
  • Allow union types as valid converters
  • Preserve existing restrictions: Greedy[str] and Greedy[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

  • If code changes were made, then they have been tested
    • I have updated the documentation to reflect the changes
    • I have formatted the code properly by running uv run nox -s lint
    • I have type-checked the code by running uv run nox -s pyright
  • 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, ...)

@shiftinv shiftinv added this to the disnake v2.12 milestone Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3.10 uniontype is not supported within commands.Greedy

2 participants