test_collections.py 文件源码

python
阅读 15 收藏 0 点赞 0 评论 0

项目:web_ctp 作者: molebot 项目源码 文件源码
def test_issue16373(self):
        # Recursion error comparing comparable and noncomparable
        # Set instances
        class MyComparableSet(Set):
            def __contains__(self, x):
                return False
            def __len__(self):
                return 0
            def __iter__(self):
                return iter([])
        class MyNonComparableSet(Set):
            def __contains__(self, x):
                return False
            def __len__(self):
                return 0
            def __iter__(self):
                return iter([])
            def __le__(self, x):
                return NotImplemented
            def __lt__(self, x):
                return NotImplemented

        cs = MyComparableSet()
        ncs = MyNonComparableSet()
        with self.assertRaises(TypeError):
            ncs < cs
        with self.assertRaises(TypeError):
            ncs <= cs
        with self.assertRaises(TypeError):
            cs > ncs
        with self.assertRaises(TypeError):
            cs >= ncs
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号