diff options
author | Mark Shannon <mark@hotpy.org> | 2022-03-04 11:31:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-04 11:31:29 (GMT) |
commit | 03c2a36b2bd2d4469160d1607619ee144175d753 (patch) | |
tree | 828a98bada6b84ea722ac104da3b7e891f44d4cd /Lib | |
parent | 8f31bf46980956c735dd18f9914f3e7144e87c77 (diff) | |
download | cpython-03c2a36b2bd2d4469160d1607619ee144175d753.zip cpython-03c2a36b2bd2d4469160d1607619ee144175d753.tar.gz cpython-03c2a36b2bd2d4469160d1607619ee144175d753.tar.bz2 |
bpo-46903: Handle str-subclasses in virtual instance dictionaries. (GH-31658)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_unicode.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 8e4e648..e97f971 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -3044,6 +3044,30 @@ class StringModuleTest(unittest.TestCase): ]]) self.assertRaises(TypeError, _string.formatter_field_name_split, 1) + def test_str_subclass_attr(self): + + name = StrSubclass("name") + name2 = StrSubclass("name2") + class Bag: + pass + + o = Bag() + with self.assertRaises(AttributeError): + delattr(o, name) + setattr(o, name, 1) + self.assertEquals(o.name, 1) + o.name = 2 + self.assertEquals(list(o.__dict__), [name]) + + with self.assertRaises(AttributeError): + delattr(o, name2) + with self.assertRaises(AttributeError): + del o.name2 + setattr(o, name2, 3) + self.assertEquals(o.name2, 3) + o.name2 = 4 + self.assertEquals(list(o.__dict__), [name, name2]) + if __name__ == "__main__": unittest.main() |