當前位置: 首頁>>代碼示例>>Python>>正文


Python abc.ABCMeta方法代碼示例

本文整理匯總了Python中collections.abc.ABCMeta方法的典型用法代碼示例。如果您正苦於以下問題:Python abc.ABCMeta方法的具體用法?Python abc.ABCMeta怎麽用?Python abc.ABCMeta使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在collections.abc的用法示例。


在下文中一共展示了abc.ABCMeta方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: isabstract

# 需要導入模塊: from collections import abc [as 別名]
# 或者: from collections.abc import ABCMeta [as 別名]
def isabstract(object):
    """Return true if the object is an abstract base class (ABC)."""
    if not isinstance(object, type):
        return False
    if object.__flags__ & TPFLAGS_IS_ABSTRACT:
        return True
    if not issubclass(type(object), abc.ABCMeta):
        return False
    if hasattr(object, '__abstractmethods__'):
        # It looks like ABCMeta.__new__ has finished running;
        # TPFLAGS_IS_ABSTRACT should have been accurate.
        return False
    # It looks like ABCMeta.__new__ has not finished running yet; we're
    # probably in __init_subclass__. We'll look for abstractmethods manually.
    for name, value in object.__dict__.items():
        if getattr(value, "__isabstractmethod__", False):
            return True
    for base in object.__bases__:
        for name in getattr(base, "__abstractmethods__", ()):
            value = getattr(object, name, None)
            if getattr(value, "__isabstractmethod__", False):
                return True
    return False 
開發者ID:CedricGuillemet,項目名稱:Imogen,代碼行數:25,代碼來源:inspect.py

示例2: abstract_class

# 需要導入模塊: from collections import abc [as 別名]
# 或者: from collections.abc import ABCMeta [as 別名]
def abstract_class(cls_):
    """Decorate a class, overriding __new__.

    Preventing a class from being instantiated similar to abc.ABCMeta
      but does not require an abstract method.
    """

    def __new__(cls, *args, **kwargs):
        if cls is cls_:
            raise TypeError('{} is an abstract class and may not be instantiated.'
                            .format(cls.__name__))
        return object.__new__(cls)
    cls_.__new__ = __new__
    return cls_ 
開發者ID:pyvista,項目名稱:pyvista,代碼行數:16,代碼來源:helpers.py

示例3: test_abstract

# 需要導入模塊: from collections import abc [as 別名]
# 或者: from collections.abc import ABCMeta [as 別名]
def test_abstract(self):
        class Abstract(abc.ABCMeta):

            @abc.abstractmethod
            def add(self, x, y):
                pass

            add5 = functools.partialmethod(add, 5)

        self.assertTrue(Abstract.add.__isabstractmethod__)
        self.assertTrue(Abstract.add5.__isabstractmethod__)

        for func in [self.A.static, self.A.cls, self.A.over_partial, self.A.nested, self.A.both]:
            self.assertFalse(getattr(func, '__isabstractmethod__', False)) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:16,代碼來源:test_functools.py


注:本文中的collections.abc.ABCMeta方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。