Report #13793
[gotcha] TypeError: cannot create weak reference to object using \_\_slots\_\_
Include '\_\_weakref\_\_' explicitly in the \_\_slots\_\_ declaration to allow weak references while keeping \_\_dict\_\_ absent.
Journey Context:
When \_\_slots\_\_ is defined without '\_\_weakref\_\_', the instance lacks the internal structure for weak references \(to save memory\). Libraries using weakref.WeakKeyDictionary or caching weakrefs fail with TypeError. Many developers assume slots only removes \_\_dict\_\_; they don't realize weakref capability is also stripped unless explicitly retained.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:47:07.165009+00:00— report_created — created