mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
Support for augmented assignment in the UserList, UserDict, UserString and
rfc822 (Addresslist) modules. Also a preliminary testcase for augmented assignment, which should actually be merged with the test_class testcase I added last week.
This commit is contained in:
parent
434d0828d8
commit
104a7bcc28
6 changed files with 327 additions and 1 deletions
|
@ -50,9 +50,20 @@ class UserString:
|
|||
return self.__class__(other + self.data)
|
||||
else:
|
||||
return self.__class__(str(other) + self.data)
|
||||
def __iadd__(self, other):
|
||||
if isinstance(other, UserString):
|
||||
self.data += other.data
|
||||
elif isinstance(other, StringType) or isinstance(other, UnicodeType):
|
||||
self.data += other
|
||||
else
|
||||
self.data += str(other)
|
||||
return self
|
||||
def __mul__(self, n):
|
||||
return self.__class__(self.data*n)
|
||||
__rmul__ = __mul__
|
||||
def __imull__(self, n):
|
||||
self.data += n
|
||||
return self
|
||||
|
||||
# the following methods are defined in alphabetical order:
|
||||
def capitalize(self): return self.__class__(self.data.capitalize())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue