[Python-Dev] RE: [Python-checkins] python/dist/src/Misc NEWS,
1.983, 1.984
Walter Dörwald
walter at livinglogic.de
Thu Jun 3 11:03:21 EDT 2004
Hye-Shik Chang wrote:
> On Thu, Jun 03, 2004 at 03:18:47PM +0200, Walter D?rwald wrote:
>
>> [...]
>>Yes, but UserString.UserString can be used to wrap both str and
>>unicode objects.
>
> Aah. Sorry. I've overlooked extensive use of UserString. :)
>
> Could you review my patch?:
> http://people.freebsd.org/~perky/userstring-width.diff
I don't think it's necessary to define iswide() and width()
only when self.data is a unicode object (in fact, self.data
might change from str to unicode during the lifetime of the
UserString object). Simply define
# the following methods are defined for unicode objects only:
def iswide(self): return self.data.iswide()
def width(self): return self.data.width()
When a str object is wrapped, an AttributeError will be raised
anyway, it shouldn't be a problem that this error is not raised
by UserString itself. You could add comments to the method like
this:
def iswide(self): return self.data.iswide() # unicode only
def width(self): return self.data.width() # unicode only
that will show up in a stacktrace and give a hint to the user.
It's good that the tests are in string_tests.py now, but you
should reuse this test class in test_unicode.py too.
Bye,
Walter Dörwald
More information about the Python-Dev
mailing list