simpler InvalidType [pr] (#13957)

simpler singleton pattern
This commit is contained in:
chenyu
2026-01-01 13:55:51 -05:00
committed by GitHub
parent b8ea0d779c
commit 8e416df438
2 changed files with 15 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
import unittest
import unittest, pickle
from tinygrad.tensor import Tensor
from tinygrad.dtype import dtypes, DType, ImageDType, PtrDType, to_dtype
from tinygrad.dtype import dtypes, DType, ImageDType, PtrDType, to_dtype, Invalid, InvalidType
class TestImageDType(unittest.TestCase):
def test_image_scalar(self):
@@ -82,5 +82,12 @@ class TestCanLosslessCast(unittest.TestCase):
self.assertTrue(can_lossless_cast(dtypes.int8, dtypes.half))
self.assertFalse(can_lossless_cast(dtypes.int8, dtypes.bfloat16))
class TestInvalidSingleton(unittest.TestCase):
def test_singleton(self):
self.assertIs(InvalidType(), InvalidType())
self.assertIs(InvalidType(), Invalid)
def test_pickle(self):
self.assertIs(pickle.loads(pickle.dumps(Invalid)), Invalid)
if __name__ == "__main__":
unittest.main()