On this page
types.DynamicClassAttribute
Prev: types.CoroutineType | Up: types | Next: types.EllipsisType
Rel: types.AsyncGeneratorType, types.BuiltinFunctionType, types.BuiltinMethodType, types.CapsuleType
Ref: docs.python.org — types.DynamicClassAttribute
Tags: #public #python3 #stdlib #types
Import
import types
from types import DynamicClassAttribute
Signature & Overview
types.DynamicClassAttribute(fget=None, fset=None, fdel=None, doc=None)
Route attribute access on a class to getattr.
Methods & Attributes
DynamicClassAttribute.deleter(self, fdel)—DynamicClassAttribute.deletermethod/property.DynamicClassAttribute.getter(self, fget)—DynamicClassAttribute.gettermethod/property.DynamicClassAttribute.setter(self, fset)—DynamicClassAttribute.settermethod/property.
Usage
import types
class Box:
value = 'class-level'
@types.DynamicClassAttribute
def value(self): return 'instance-level'
assert Box().value == 'instance-level'
Gotchas
- Routes instance access to the getter while allowing class-level attribute lookup (powers
enum.Enum.value).
REPL Inspect
from types import DynamicClassAttribute
help(DynamicClassAttribute)
Linked from
Related notes
- tuts/python3/stdlib_module/types/CoroutineType Linked here; links to this page; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/EllipsisType Linked here; links to this page; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/types/AsyncGeneratorType Linked here; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/BuiltinFunctionType Linked here; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/BuiltinMethodType Linked here; shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/CapsuleType Linked here; shared tags: #stdlib, #types
- tuts/c/stdlib/stdint_stdbool_and_limits shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/CellType shared tags: #stdlib, #types
- tuts/python3/stdlib_module/types/ClassMethodDescriptorType shared tags: #stdlib, #types