traits icon indicating copy to clipboard operation
traits copied to clipboard

Use | operator for Union traits

Open corranwebster opened this issue 3 years ago • 1 comments

Following PEP 604 which allows constructs like int | float as a replacement for Union[int, float] should we allow Int | Float as an (optional) replacement for Union(Int, Float)?

The good:

  • meaning is fairly clear
  • alignment with Python typing

The bad:

  • if you want metadata then you'd have to do something like (Int | Float)(foo='bar') which is not very clear compared to Union(Int, Float, foo='bar')

The ugly:

  • Int | Float or Int() | Float()? It may have to be the latter, but presumably Python is going to grow some hook for | for types with this change, the same way it did for getitem.

corranwebster avatar Feb 03 '21 09:02 corranwebster

Note that PEP 593 allows you to annotate annotations with metadata.

thedrow avatar Apr 08 '21 07:04 thedrow