MCPcopy Index your code
hub / github.com/python/cpython / testSetattrWrapperNameIntern

Method testSetattrWrapperNameIntern

Lib/test/test_class.py:656–674  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

654
655 @cpython_only
656 def testSetattrWrapperNameIntern(self):
657 # Issue #25794: __setattr__ should intern the attribute name
658 class A:
659 pass
660
661 def add(self, other):
662 return 'summa'
663
664 name = str(b'__add__', 'ascii') # shouldn't be optimized
665 self.assertIsNot(name, '__add__') # not interned
666 type.__setattr__(A, name, add)
667 self.assertEqual(A() + 1, 'summa')
668
669 name2 = str(b'__add__', 'ascii')
670 self.assertIsNot(name2, '__add__')
671 self.assertIsNot(name2, name)
672 type.__delattr__(A, name2)
673 with self.assertRaises(TypeError):
674 A() + 1
675
676 def testSetattrNonStringName(self):
677 class A:

Callers

nothing calls this directly

Calls 7

strFunction · 0.85
assertIsNotMethod · 0.80
AClass · 0.70
__setattr__Method · 0.45
assertEqualMethod · 0.45
__delattr__Method · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected