MCPcopy Index your code
hub / github.com/RustPython/RustPython / testSetattrWrapperNameIntern

Method testSetattrWrapperNameIntern

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

Source from the content-addressed store, hash-verified

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