All fields

“Descriptors & Properties” in Information Technology

30 questions across 2 technologies.

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
11How does Python's own implementation of instance methods use the descriptor protocol to achieve automatic 'self' binding? Python › Descriptors & PropertiesPythonDescriptors & PropertiesAdvanced
12How do you implement a descriptor-based ORM-style field that lazily loads related data only when actually accessed? Python › Descriptors & PropertiesPythonDescriptors & PropertiesAdvanced
13How would you write a descriptor supporting attribute DELETION via __delete__, and what real use case does that enable? Python › Descriptors & PropertiesPythonDescriptors & PropertiesAdvanced
14How would you use a WeakKeyDictionary inside a descriptor to store per-instance data without relying on the instance's own __dict__ or requiring a dedicated __slots__ entry? Python › Descriptors & PropertiesPythonDescriptors & PropertiesAdvanced
15How does @property's read-only behavior (no setter defined) actually raise an AttributeError, and how would you customize that error message? Python › Descriptors & PropertiesPythonDescriptors & PropertiesAdvanced
16How do you destructure properties out of an object? JavaScript › Destructuring, Spread & RestJavaScriptDestructuring, Spread & RestBeginner
17What are class fields, and how do they differ from constructor-assigned properties? JavaScript › Classes & Class SyntaxJavaScriptClasses & Class SyntaxIntermediate
18What is a metaclass in Python, and what is the default metaclass for all classes? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationBeginner
19How does __call__ let an instance of a class be invoked like a function? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
20How do you implement custom attribute access with __getattr__ versus __getattribute__? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
21What role does the class namespace dict play during class creation, and how can __prepare__ customize it? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationIntermediate
22How does __set_name__ let a descriptor discover the attribute name it's assigned to within a class? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationIntermediate
23What is a mixin class, and how does it differ from a typical base class in multiple inheritance? Python › Multiple Inheritance & MROPythonMultiple Inheritance & MROIntermediate
24How would you implement a custom, memory-efficient data structure using __slots__ instead of a regular class with a __dict__? Python › Data Types & StructuresPythonData Types & StructuresAdvanced
25What is functools.cached_property and how does it differ from @property combined with manual caching? Python › functools & Functional Programming ToolsPythonfunctools & Functional Programming ToolsAdvanced
26Why is caution needed when applying @lru_cache directly to instance methods? Python › functools & Functional Programming ToolsPythonfunctools & Functional Programming ToolsAdvanced
27How does __slots__ interact with magic methods and instance attribute storage? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingAdvanced
28Why can't you freely mix two classes with different, incompatible metaclasses in multiple inheritance? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationAdvanced
29How can a metaclass be used to implement the Singleton design pattern more robustly than overriding __new__ alone? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationAdvanced
30How does Python handle attribute (not just method) resolution across multiple inheritance, and can it lead to surprising shadowing? Python › Multiple Inheritance & MROPythonMultiple Inheritance & MROAdvanced