MCPcopy Create free account
hub / github.com/vispy/vispy / classmethod

Method classmethod

vispy/ext/cocoapy.py:867–889  ·  view source on GitHub ↗

Function decorator for class methods.

(self, encoding)

Source from the content-addressed store, hash-verified

865 return decorator
866
867 def classmethod(self, encoding):
868 """Function decorator for class methods."""
869 # Add encodings for hidden self and cmd arguments.
870 encoding = ensure_bytes(encoding)
871 typecodes = parse_type_encoding(encoding)
872 typecodes.insert(1, b'@:')
873 encoding = b''.join(typecodes)
874
875 def decorator(f):
876 def objc_class_method(objc_cls, objc_cmd, *args):
877 py_cls = ObjCClass(objc_cls)
878 py_cls.objc_cmd = objc_cmd
879 args = convert_method_arguments(encoding, args)
880 result = f(py_cls, *args)
881 if isinstance(result, ObjCClass):
882 result = result.ptr.value
883 elif isinstance(result, ObjCInstance):
884 result = result.ptr.value
885 return result
886 name = f.__name__.replace('_', ':')
887 self.add_class_method(objc_class_method, name, encoding)
888 return objc_class_method
889 return decorator
890
891
892# XXX This causes segfaults in all backends (yikes!), and makes it so that

Callers

nothing calls this directly

Calls 3

ensure_bytesFunction · 0.85
parse_type_encodingFunction · 0.85
insertMethod · 0.45

Tested by

no test coverage detected