Currently, beartype doesn't work, as it requires types' __repr__ results to be consistent, but Unions currently just return f"{obj.__module__}.{obj.__qualname__}" for each element in the union. This doesn't preserve any nptyping info, so beartype gets angry.
This fix just makes the | (or) operator return a subclass of Union with __repr__ overwritten so that it just calls __repr__ on each underlying type.
Currently,
beartype
doesn't work, as it requires types'__repr__
results to be consistent, but Unions currently just returnf"{obj.__module__}.{obj.__qualname__}"
for each element in the union. This doesn't preserve any nptyping info, sobeartype
gets angry.This fix just makes the
|
(or) operator return a subclass ofUnion
with__repr__
overwritten so that it just calls__repr__
on each underlying type.