python类with_metaclass()的实例源码

types.py 文件源码 项目:magic-constraints 作者: huntzhan 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def generate_immutable_abc(supercls, mutable_subclass):

    class ABCImmutableMeta(ABCMeta):

        def __subclasscheck__(cls, subclass):
            if not issubclass(subclass, supercls):
                return False
            return not issubclass(subclass, mutable_subclass)

    class ABCImmutable(with_metaclass(ABCImmutableMeta, object)):
        pass

    # dirty hack to assert issubclass(ABCImmutable, supercls).
    supercls._abc_cache.add(ABCImmutable)

    return ABCImmutable
types.py 文件源码 项目:magic-constraints 作者: huntzhan 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __new__(generator_cls, ABC):
        MetaMagicType = create_metaclass(
            BasicMetaMagicType,
            generator_cls,
        )
        MagicType = create_class(
            with_metaclass(MetaMagicType, BasicMagicType),
            generator_cls,
        )

        MagicType.generator_cls = generator_cls
        MagicType.main_cls = ABC
        MagicType.partial_cls = None

        return MagicType
test_mapper.py 文件源码 项目:kiwi 作者: papaya-mobile 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_inherit_2(self):
        class Hi(TableBase):
            id = HashKeyField()

        class Table(with_metaclass(TableMeta, Hi)):
            pass

        class User(Table, Hi):
            name = RangeKeyField(data_type=NUMBER)

        self._check_rangekey(User)
test_dict.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_with_metaclass_and_dict(self):
        """
        Issue #91 (for newdict instead of newobject)
        """
        from future.utils import with_metaclass

        class MetaClass(type):
            pass

        class TestClass(with_metaclass(MetaClass, dict)):
            pass
test_str.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_with_metaclass_and_str(self):
        """
        Issue #91 (for newstr instead of newobject)
        """
        from future.utils import with_metaclass

        class MetaClass(type):
            pass

        class TestClass(with_metaclass(MetaClass, str)):
            pass
test_int.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_with_metaclass_and_int(self):
        """
        Issue #91 (for newint instead of newobject)
        """
        from future.utils import with_metaclass

        class MetaClass(type):
            pass

        class TestClass(with_metaclass(MetaClass, int)):
            pass
test_list.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_with_metaclass_and_list(self):
        """
        Issue #91 (for newdict instead of newobject)
        """
        from future.utils import with_metaclass

        class MetaClass(type):
            pass

        class TestClass(with_metaclass(MetaClass, list)):
            pass
test_object.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_with_metaclass_and_object(self):
        """
        Issue #91
        """
        from future.utils import with_metaclass

        class MetaClass(type):
            pass

        class TestClass(with_metaclass(MetaClass, object)):
            pass


问题


面经


文章

微信
公众号

扫码关注公众号