ramonhagenaars / nptyping

💡 Type hints for Numpy and Pandas
MIT License
589 stars 30 forks source link

hack to enable compatability with beartype and generally improve Union functionality #123

Open reid23 opened 3 months ago

reid23 commented 3 months ago

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.