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.
Created on 2009年01月23日 15:02 by Taldor, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| weakref_unicode.patch | benjamin.peterson, 2009年01月24日 18:43 | |||
| Messages (7) | |||
|---|---|---|---|
| msg80416 - (view) | Author: (Taldor) | Date: 2009年01月23日 15:02 | |
Calling the unicode function on a proxy object, doesn't use the proxi-ed object's __unicode__ method, but its __str__ method. >>> class A(object): ... def __str__(self): ... return "str" ... def __unicode__(self): ... return "unicode" ... >>> a = A() >>> unicode(a) u'unicode' >>> import weakref >>> b = weakref.proxy(a) >>> unicode(b) u'str' I expected the last result to be u'unicode'. I did get u'unicode' in Python 2.5 (but not in 2.6). |
|||
| msg80423 - (view) | Author: Gabriel Genellina (ggenellina) | Date: 2009年01月24日 00:06 | |
Same results on trunk. |
|||
| msg80433 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2009年01月24日 02:05 | |
This was broken by r64791. The problem is that PyObject_Unicode now uses _PyType_Lookup instead of PyObject_GetItem, so that the proxy's custom __getattr__ implementation is bypassed. |
|||
| msg80455 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2009年01月24日 15:34 | |
weakref.proxy needs to be fixed to delegate the unicode slot correctly. >>> from weakref import proxy >>> "__unicode__" in dir(type(proxy(Exception))) False That predicate must return true in order for the delegation to do the right thing (this is actually the case for all of the slots and pseudo-slots that can bypass __getattribute__ on the instance object - it's just that most of them are already handled correctly). This need to explicitly delegate all supported slots is the reason why weakref proxy instances add so many magic method stubs when compared to the actual interface of the underlying class: >>> len(set(dir(type(proxy(Exception)))) - set(dir(Exception))) 53 |
|||
| msg80468 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2009年01月24日 18:43 | |
Here's a patch. |
|||
| msg95422 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2009年11月18日 12:01 | |
Patch looks good to me. |
|||
| msg95463 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2009年11月19日 03:01 | |
Fixed in r76395. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:44 | admin | set | github: 49287 |
| 2009年11月19日 03:01:08 | benjamin.peterson | set | status: open -> closed resolution: fixed messages: + msg95463 |
| 2009年11月18日 12:01:11 | ncoghlan | set | messages: + msg95422 |
| 2009年01月24日 18:43:10 | benjamin.peterson | set | priority: high keywords: + needs review, patch messages: + msg80468 files: + weakref_unicode.patch |
| 2009年01月24日 15:34:20 | ncoghlan | set | messages: + msg80455 |
| 2009年01月24日 02:05:58 | benjamin.peterson | set | nosy:
+ ncoghlan, benjamin.peterson messages: + msg80433 |
| 2009年01月24日 00:06:07 | ggenellina | set | nosy:
+ ggenellina title: unexpected unicode behavior for proxy objects -> unicode(x) for weakref.proxy objects invokes __str__ instead of __unicode__ messages: + msg80423 components: + Interpreter Core, - None versions: + Python 2.7 |
| 2009年01月23日 15:02:41 | Taldor | create | |