Skip to content

Commit abb34fe

Browse files
committed
UserString.MutableString has been removed in Python 3.0.
Works on issue python#2877. Thanks Quentin Gallet-Gilles for the patch.
1 parent 5ec330c commit abb34fe

5 files changed

Lines changed: 22 additions & 2 deletions

File tree

Doc/library/userdict.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ The :mod:`UserString` module defines the following classes:
178178
mutable object as dictionary key, which would be otherwise very error prone and
179179
hard to track down.
180180

181+
.. deprecated:: 2.6
182+
The :class:`MutableString` class has been removed in Python 3.0.
183+
181184
In addition to supporting the methods and operations of string and Unicode
182185
objects (see section :ref:`string-methods`), :class:`UserString` instances
183186
provide the following attribute:

Lib/UserString.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ class MutableString(UserString, collections.MutableSequence):
146146
147147
A faster and better solution is to rewrite your program using lists."""
148148
def __init__(self, string=""):
149+
from warnings import warnpy3k
150+
warnpy3k('the class UserString.MutableString has been removed in '
151+
'Python 3.0', stacklevel=2)
149152
self.data = string
150153
def __hash__(self):
151154
raise TypeError, "unhashable type (it is mutable)"

Lib/test/test_py3kwarn.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ def test_commands_members(self):
219219
func = getattr(commands, name)
220220
self.assertRaises(DeprecationWarning, func, *([None]*arg_count))
221221

222+
def test_mutablestring_removal(self):
223+
# UserString.MutableString has been removed in 3.0.
224+
import UserString
225+
with catch_warning(record=False):
226+
warnings.filterwarnings("error", ".*MutableString",
227+
DeprecationWarning)
228+
self.assertRaises(DeprecationWarning, UserString.MutableString)
229+
222230

223231
def test_main():
224232
with catch_warning(record=True):

Lib/test/test_userstring.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import string
66
from test import test_support, string_tests
7-
87
from UserString import UserString, MutableString
8+
import warnings
99

1010
class UserStringTest(
1111
string_tests.CommonTest,
@@ -135,7 +135,10 @@ def test_imul(self):
135135
self.assertEqual(s, "")
136136

137137
def test_main():
138-
test_support.run_unittest(UserStringTest, MutableStringTest)
138+
with test_support.catch_warning(record=False):
139+
warnings.filterwarnings("ignore", ".*MutableString",
140+
DeprecationWarning)
141+
test_support.run_unittest(UserStringTest, MutableStringTest)
139142

140143
if __name__ == "__main__":
141144
test_main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ Extension Modules
6363
Library
6464
-------
6565

66+
Issue #2877 - The UserString.MutableString class has been removed in
67+
Python 3.0.
68+
6669
- Do not close external file objects passed to tarfile.open(mode='w:bz2')
6770
when the TarFile is closed.
6871

0 commit comments

Comments
 (0)