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

Method test_subclassing

Lib/test/test_typing.py:7751–7818  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

7749 typing.AsyncGenerator[int, int]()
7750
7751 def test_subclassing(self):
7752
7753 class MMA(typing.MutableMapping):
7754 pass
7755
7756 with self.assertRaises(TypeError): # It's abstract
7757 MMA()
7758
7759 class MMC(MMA):
7760 def __getitem__(self, k):
7761 return None
7762 def __setitem__(self, k, v):
7763 pass
7764 def __delitem__(self, k):
7765 pass
7766 def __iter__(self):
7767 return iter(())
7768 def __len__(self):
7769 return 0
7770
7771 self.assertEqual(len(MMC()), 0)
7772 self.assertTrue(callable(MMC.update))
7773 self.assertIsInstance(MMC(), typing.Mapping)
7774
7775 class MMB(typing.MutableMapping[KT, VT]):
7776 def __getitem__(self, k):
7777 return None
7778 def __setitem__(self, k, v):
7779 pass
7780 def __delitem__(self, k):
7781 pass
7782 def __iter__(self):
7783 return iter(())
7784 def __len__(self):
7785 return 0
7786
7787 self.assertEqual(len(MMB()), 0)
7788 self.assertEqual(len(MMB[str, str]()), 0)
7789 self.assertEqual(len(MMB[KT, VT]()), 0)
7790
7791 self.assertNotIsSubclass(dict, MMA)
7792 self.assertNotIsSubclass(dict, MMB)
7793
7794 self.assertIsSubclass(MMA, typing.Mapping)
7795 self.assertIsSubclass(MMB, typing.Mapping)
7796 self.assertIsSubclass(MMC, typing.Mapping)
7797
7798 self.assertIsInstance(MMB[KT, VT](), typing.Mapping)
7799 self.assertIsInstance(MMB[KT, VT](), collections.abc.Mapping)
7800
7801 self.assertIsSubclass(MMA, collections.abc.Mapping)
7802 self.assertIsSubclass(MMB, collections.abc.Mapping)
7803 self.assertIsSubclass(MMC, collections.abc.Mapping)
7804
7805 with self.assertRaises(TypeError):
7806 issubclass(MMB[str, str], typing.Mapping)
7807 self.assertIsSubclass(MMC, MMA)
7808

Callers

nothing calls this directly

Calls 12

MMAClass · 0.85
lenFunction · 0.85
MMCClass · 0.85
callableFunction · 0.85
MMBClass · 0.85
issubclassFunction · 0.85
assertTrueMethod · 0.80
assertIsInstanceMethod · 0.80
assertRaisesMethod · 0.45
assertEqualMethod · 0.45
assertNotIsSubclassMethod · 0.45
assertIsSubclassMethod · 0.45

Tested by

no test coverage detected