Allow Greedy[X] | Y

Constructs a Union. Needs to be special instance behavior due to
`__class_getitem__` being implemented to return an instance not a type
or GenericAlias.
This commit is contained in:
Michael H
2026-07-08 16:15:06 -04:00
committed by GitHub
parent cc00d56a22
commit 7057cb10c0
+3
View File
@@ -1140,6 +1140,9 @@ class Greedy(List[T]):
converter = getattr(self.converter, '__name__', repr(self.converter))
return f'Greedy[{converter}]'
def __or__(self, value: Any) -> Any:
return Union[self, value]
def __class_getitem__(cls, params: Union[Tuple[T], T]) -> Greedy[T]:
if not isinstance(params, tuple):
params = (params,)