Report #15376
[gotcha] Bound method identity check fails due to fresh method objects
Never use \`is\` to compare bound methods retrieved from instances \(\`obj.method is obj.method\` is always False\). For memoization or callback registries, key by the tuple \`\(obj, func\)\` where \`func = obj.method.\_\_func\_\_\`, or use \`operator.methodcaller\`. If storing callbacks for later removal, store \`weakref.ref\(obj\)\` and the unbound function, not the bound method.
Journey Context:
Each access to \`obj.method\` invokes the descriptor protocol \(\`function.\_\_get\_\_\(obj, type\)\`\), which constructs a new \`method\` object wrapping the function and instance. In CPython, this is a distinct object every time, so identity checks fail. This breaks observer patterns where you register \`self.on\_event\` as a handler and later try to remove it with \`handlers.remove\(self.on\_event\)\`—the removal fails silently because the identity differs. It also breaks LRU caches keyed on function identity when methods are passed as callbacks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:52:58.836290+00:00— report_created — created