Thank you both for the answers
```python
def union( name: str, types: Tuple[Types, ...], * ) -> Union[Types]: # implementation is not important return None # type: ignore ```
I think the (non) implementation as shown is confusing. You surely don't actually return None? What do you do with the name, just ignore it?
The implementation returns an instance of a custom defined union class,
which holds the information about the types and the name.
I think a better implementation would be to return Annotated[Union[*Types],
Something(name="passed name")],
but that would have the same issue I'm having now, since I'm passing
through a function call.
I think I can ask my users to use Annotated directly đ
My goal with a custom union function was ease of use, I wanted something
that didn't require to learn new concepted (Annotated)
and it was easier to type:
```python
UserOrError = strawberry.union((User, Error), "UserOrError")]
# vs
UserOrError = Annotated[User|Error, strawberry.union("UserOrError")]
```
but maybe Annotated doesn't look too bad, especially with the new union
syntax đ
Thanks Steven and Eric!
On Sat, 11 Jun 2022 at 00:48, Steven D'Aprano
Hi Patrick,
On Fri, Jun 10, 2022 at 12:42:16PM -0000, Patrick Arminio wrote:
```python def union( name: str, types: Tuple[Types, ...], * ) -> Union[Types]: # implementation is not important return None # type: ignore ```
I think the (non) implementation as shown is confusing. You surely don't actually return None? What do you do with the name, just ignore it?
If you ignore the name, then it is hard for me to see why you need this union function at all.
```python UserOrError = User|Error
# Or if you need to annotate it with additional information: UserOrError = Annotated[User|Error, "UserOrError"] ```
As Eric explains in another post, it is unlikely that static (compile-time) type checkers will support the evaluation and tracking of arbitrary types generated at runtime.
Unfortunately subscripting syntax does not allow keyword arguments, so you cannot associate your annotation with a parameter name:
``` # This is a syntax error. Annotated[User|Error, name="UserOrError"] ```
See rejected PEP 637.
-- Steve _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: patrick.arminio@gmail.com
-- Patrick Arminio