Report #36226
[gotcha] Instance dictionary shadows non-data descriptors but not data descriptors
When implementing custom descriptors, implement \_\_set\_\_ to make it a data descriptor if you want to prevent instance dictionary shadowing. For methods \(non-data descriptors\), accept that assignment shadows the method.
Journey Context:
Python attribute lookup follows: data descriptors \(have \_\_set\_\_\) are checked before instance dict, but non-data descriptors \(only \_\_get\_\_\) are checked after instance dict. This means 'obj.method = 5' shadows the function descriptor, but 'obj.property = 5' triggers the property's \_\_set\_\_. The footgun: developers implementing custom descriptors often forget to add a dummy \_\_set\_\_ \(or raise AttributeError in it\) to make it a data descriptor, then are surprised when instance assignment bypasses their descriptor entirely. This affects ORMs and validation libraries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:17:11.960255+00:00— report_created — created