In the context of the Descriptor Protocol, what is the primary difference between a data descriptor and a non-data descriptor?
Trap 1: Non-data descriptors can override instance dictionary lookup.
Only data descriptors have priority over instance __dict__ lookups.
Trap 2: Data descriptors only function with class attributes.
Data descriptors work on both instance and class levels.
Trap 3: Non-data descriptors are always read-only.
They are just descriptors that lack set/delete logic; read-only is a property of the implementation.
- A
Non-data descriptors can override instance dictionary lookup.
Why wrong: Only data descriptors have priority over instance __dict__ lookups.
- B
Data descriptors define __set__ or __delete__, whereas non-data descriptors do not.
This is the strict definition of the descriptor protocol's precedence.
- C
Data descriptors only function with class attributes.
Why wrong: Data descriptors work on both instance and class levels.
- D
Non-data descriptors are always read-only.
Why wrong: They are just descriptors that lack set/delete logic; read-only is a property of the implementation.