Issue1775263

classification
Title: patch for bug [1768979]:hasattr,getattr
Type: Severity: normal
Components: Core Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ayeshaiqbal, cgroves, pjenvey
Priority: normal Keywords: patch

Created on 2007-08-16.09:20:53 by ayeshaiqbal, last changed 2008-04-09.05:32:51 by pjenvey.

Files
File name Uploaded Description Edit Remove
hasattr.patch ayeshaiqbal, 2007-08-23.05:05:41 patch file
Messages
msg2811 (view) Author: ayesha (ayeshaiqbal) Date: 2007-08-16.09:20:53
This fix checks whether the attribute string is unicode.If SO a UnicodeError is raised.The test file test_builtin now executes without any error
Thanks,
Ayesha
msg2812 (view) Author: Philip Jenvey (pjenvey) Date: 2007-08-22.23:34:41
throwing a UnicodeError here isn't the same as CPython. Since CPython is dealing with an actual unicode object, it will encode() it, and when the encoding fails you'll end up with the typical UnicodeEncodeError: 'ascii' codec can't encode character u'\xe' in position 0: ordinal not in range(128)

This patch's behavior is similar, but python code will be expecting to catch UnicodeEncodeErrors when these operations fail, not its base class UnicodeError.

You might want to force an encode operation here instead. If encode() is much slower than isunicode, maybe only encode() if isunicode() returns true. You could also throw the UnicodeEncodeError yourself, but preserving the full UnicodeEncodeError's message with the failed character and its position is preferable -- for developers to see exactly why it failed
msg2813 (view) Author: ayesha (ayeshaiqbal) Date: 2007-08-23.05:05:41
That was a valuable suggestion .I have made the necessary changes and uploaded the new patch
File Added: hasattr.patch
msg2814 (view) Author: Charlie Groves (cgroves) Date: 2007-09-22.19:13:34
It makes more sense for this check to live in __findattr__(PyString) instead of __findattr__(String).  The first place would allow you to do an instanceof PyUnicode check instead of making a PyString out of every String that comes in to __findattr__.  __findattr__ is used from all over the place, so slowing it down is a bad idea.  If some Java code is calling __findattr__(String) with unicode Strings, this should be fixed there rather than in PyObject.  

Also, you're using tabs rather than spaces for indentation.
msg3145 (view) Author: Philip Jenvey (pjenvey) Date: 2008-04-09.05:32:51
we actually don't want the check inside of __findattr__, CPython has these 
checks in the hasattr and getattr functions. I've added them in r4324

thanks though, Ayesha
History
Date User Action Args
2008-04-09 05:32:51pjenveysetstatus: open -> closed
resolution: fixed
messages: + msg3145
components: + Core, - None
2007-08-16 09:20:53ayeshaiqbalcreate