type.go 430 B

123456789101112131415161718192021222324252627
  1. package python
  2. /*
  3. #define PY_SSIZE_T_CLEAN
  4. #include <Python.h>
  5. */
  6. import "C"
  7. //
  8. // Type
  9. //
  10. type Type struct {
  11. Object *C.PyTypeObject
  12. }
  13. func NewType(pyTypeObject *C.PyTypeObject) *Type {
  14. return &Type{pyTypeObject}
  15. }
  16. func (self *Type) IsSubtype(type_ *Type) bool {
  17. return C.PyType_IsSubtype(self.Object, type_.Object) != 0
  18. }
  19. func (self *Type) HasFlag(flag C.ulong) bool {
  20. return C.PyType_GetFlags(self.Object)&flag != 0
  21. }