ramonhagenaars / nptyping

💡 Type hints for Numpy and Pandas
MIT License
576 stars 29 forks source link

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

Open reid23 opened 1 month ago

reid23 commented 1 month 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.