mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Change sys.intern() so that unicode strings can be
interned too. Add a test for this.
This commit is contained in:
parent
360b01a663
commit
2a0c081470
2 changed files with 25 additions and 7 deletions
|
|
@ -356,7 +356,7 @@ class SysModuleTest(unittest.TestCase):
|
|||
# We don't want them in the interned dict and if they aren't
|
||||
# actually interned, we don't want to create the appearance
|
||||
# that they are by allowing intern() to succeeed.
|
||||
class S(str):
|
||||
class S(str8):
|
||||
def __hash__(self):
|
||||
return 123
|
||||
|
||||
|
|
@ -368,6 +368,17 @@ class SysModuleTest(unittest.TestCase):
|
|||
setattr(s, s, s)
|
||||
self.assertEqual(getattr(s, s), s)
|
||||
|
||||
s = "never interned as unicode before"
|
||||
self.assert_(sys.intern(s) is s)
|
||||
s2 = s.swapcase().swapcase()
|
||||
self.assert_(sys.intern(s2) is s)
|
||||
|
||||
class U(str):
|
||||
def __hash__(self):
|
||||
return 123
|
||||
|
||||
self.assertRaises(TypeError, sys.intern, U("abc"))
|
||||
|
||||
|
||||
def test_main():
|
||||
test.test_support.run_unittest(SysModuleTest)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue