This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
| Author | ncoghlan |
|---|---|
| Recipients | georg.brandl, jkrukoff, ncoghlan, terry.reedy |
| Date | 2008年04月08日.16:10:12 |
| SpamBayes Score | 0.0047784336 |
| Marked as misclassified | No |
| Message-id | <1207671013.9.0.764781222134.issue643841@psf.upfronthosting.co.za> |
| In-reply-to |
| Content | |
|---|---|
I spent an enlightening evening browsing through the source code for weakref.proxy. The way that code works is to define every slot, delegating to the proxied object to handle each call (wrapping and unwrapping the proxied object as needed). This is normally transparent to the user due to the fact that __getattribute__ is one of the proxied methods (and at the C level, the delegated slot invocations return NotImplemented or set the appropriate exceptions). The only way it shows through is the fact that operator.isNumber and operator.isMapping will always return True for the proxy instance, and operator.isSequence will always return False - this is due to the proxy type filling in the number and mapping slots, but not the sequence slots. However, this prompted me to try an experiment (Python 2.5.1), and the results didn't fill me with confidence regarding the approach of expecting 3rd party developers to explicitly delegate all of the special methods: >>> class Demo: ... def __index__(self): ... return 1 ... >>> a = Demo() >>> b = weakref.proxy(a) >>> operator.index(a) 1 >>> operator.index(b) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'weakproxy' object cannot be interpreted as an index Oops. |
|
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008年04月08日 16:10:15 | ncoghlan | set | spambayes_score: 0.00477843 -> 0.0047784336 recipients: + ncoghlan, georg.brandl, terry.reedy, jkrukoff |
| 2008年04月08日 16:10:13 | ncoghlan | set | spambayes_score: 0.00477843 -> 0.00477843 messageid: <1207671013.9.0.764781222134.issue643841@psf.upfronthosting.co.za> |
| 2008年04月08日 16:10:13 | ncoghlan | link | issue643841 messages |
| 2008年04月08日 16:10:12 | ncoghlan | create | |