numerary icon indicating copy to clipboard operation
numerary copied to clipboard

`numpy` primitives no longer validate on assignment

Open posita opened this issue 3 years ago • 1 comments

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 avatar Jul 07 '22 01:07 posita

[deleted]

posita avatar Jul 07 '22 02:07 posita