1# mode: run 2# tag: tpflags, type_version_tag 3 4cimport cython 5 6 7cdef extern from *: 8 unsigned long PY_VERSION_HEX 9 unsigned long Py_TPFLAGS_HAVE_VERSION_TAG 10 ctypedef struct PyTypeObject: 11 unsigned long tp_flags 12 13 14def test_flag(t): 15 return ((<PyTypeObject*>t).tp_flags & Py_TPFLAGS_HAVE_VERSION_TAG) != 0 16 17 18cdef class ImplicitAttrCache(object): 19 """ 20 >>> flag = test_flag(ImplicitAttrCache) 21 >>> print(flag) 22 True 23 """ 24 cdef public int x 25 cdef object y 26 27 28@cython.type_version_tag(True) 29cdef class ExplicitAttrCache(object): 30 """ 31 >>> flag = test_flag(ImplicitAttrCache) 32 >>> print(flag) 33 True 34 """ 35 cdef public int x 36 cdef object y 37 38 39@cython.type_version_tag(False) 40cdef class NoAttrCache(object): 41 """ 42 >>> test_flag(NoAttrCache) 43 False 44 """ 45 cdef public int x 46 cdef object y 47 48