30 questions for “Descriptors & Properties”

Found in 1 field. Select a question to see its full answer.

Information Technology

30 questions in 2 technologies

#QuestionTechnologyTopicLevel
1How do properties and descriptors interact with __slots__, and what special consideration is needed? Python › Descriptors & PropertiesPythonDescriptors & PropertiesAdvanced
2What does the @property decorator do, and how does it let a method be accessed like an attribute? Python › Descriptors & PropertiesPythonDescriptors & PropertiesBeginner
3How do you add a setter to a property so assignment (obj.attr = value) triggers custom logic, like validation? Python › Descriptors & PropertiesPythonDescriptors & PropertiesBeginner
4How would you convert an existing plain attribute into a property later, without breaking any existing code that reads or writes it directly? Python › Descriptors & PropertiesPythonDescriptors & PropertiesBeginner
5What is a descriptor, and which dunder methods define the descriptor protocol? Python › Descriptors & PropertiesPythonDescriptors & PropertiesIntermediate
6What is the difference between a data descriptor and a non-data descriptor, and how does this affect attribute lookup priority? Python › Descriptors & PropertiesPythonDescriptors & PropertiesIntermediate
7How does __set_name__ let a descriptor automatically learn the attribute name it's being assigned to on the owning class? Python › Descriptors & PropertiesPythonDescriptors & PropertiesIntermediate
8How would you implement a lazy, cached property using a custom descriptor (or functools.cached_property) that only computes its value once? Python › Descriptors & PropertiesPythonDescriptors & PropertiesAdvanced
9How do you write a descriptor that behaves differently when accessed on the CLASS itself versus on an INSTANCE? Python › Descriptors & PropertiesPythonDescriptors & PropertiesAdvanced
10How would you implement a type-validating descriptor that enforces a specific type constraint, reusable across multiple attributes and classes? Python › Descriptors & PropertiesPythonDescriptors & PropertiesAdvanced