beartype / numerary

A pure-Python codified rant aspiring to a world where numbers and types can work together.
https://posita.github.io/numerary/latest/
Other
39 stars 1 forks source link

`numpy` primitives no longer validate on assignment #16

Open posita opened 2 years ago

posita commented 2 years ago

Apparently, numpy upped its typing game, which is cool, but it makes it very hard to validate using something as rudimentary as numerary. Currently, the work-around I've found is something like the following:

# workaround.py
from numerary.types import SupportsFloorCeil
import numpy

uint8_val_typed: SupportsFloorCeil = numpy.uint8(2)  # fails
uint8_val_asserted = numpy.uint8(2)
assert isinstance(uint8_val_asserted, SupportsFloorCeil)  # works
reveal_type(uint8_val_asserted)  # workaround.<subclass of "unsignedinteger" and "SupportsFloorCeil">
posita commented 2 years ago

[deleted]