objc: fix _classmethods_ dispatch flag (#14854)

* objc: fix _classmethods_ dispatch flag

* test: add objc _classmethods_ regression
This commit is contained in:
Kartik Vashishta 2026-04-20 11:35:03 +10:00 committed by GitHub
commit a1696e8413
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

17
test/unit/test_objc.py Normal file
View file

@ -0,0 +1,17 @@
import sys, unittest
class TestObjCMetaSpec(unittest.TestCase):
@unittest.skipUnless(sys.platform == "darwin", "objc runtime only on macOS")
def test_classmethods_are_classmethods(self):
from tinygrad.runtime.support.objc import Spec, id_
#_classmethods_ must include classmethod descriptors
class ObjCTest(Spec):
_methods_ = [("foo", id_, [])]
_classmethods_ = [("bar", id_, [])]
self.assertNotIsInstance(ObjCTest.__dict__["foo"], classmethod)
self.assertIsInstance(ObjCTest.__dict__["bar"], classmethod)
if __name__ == "__main__":
unittest.main()

View file

@ -49,7 +49,7 @@ else:
def __setattr__(cls, k, v):
super().__setattr__(k, v)
if k in ("_methods_", "_classmethods_"):
for m in v: cls._addmeth(m, clsmeth=(v=="_classmethods_"))
for m in v: cls._addmeth(m, clsmeth=(k=="_classmethods_"))
for c in cls._children_: c._inherit(cls)
if k == "_bases_":
for b in v: