Created
April 20, 2017 22:49
-
-
Save Tinche/678a2f97f656421ab65338ea678df354 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cpython.object cimport descrgetfunc, Py_TYPE | |
cdef class FrozenSlotDescriptor(object): | |
""" | |
Wraps the normal Python slot descriptor, disabling write access. | |
""" | |
cdef descrgetfunc get | |
cdef object descriptor | |
def __cinit__(self, orig): | |
self.descriptor = orig | |
self.get = Py_TYPE(orig).tp_descr_get | |
def __get__(self, obj, type): | |
return self.get(self.descriptor, obj, type) | |
def __set__(self, obj, value): | |
raise AttributeError('This attribute is frozen.') | |
def __delete__(self, obj): | |
raise AttributeError('This attribute is frozen.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment