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


Python abc.ABC屬性代碼示例

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


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

示例1: _process_class

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def _process_class(cls, letter_case, undefined):
    if letter_case is not None or undefined is not None:
        cls.dataclass_json_config = config(letter_case=letter_case,
                                           undefined=undefined)[
            'dataclasses_json']

    cls.to_json = DataClassJsonMixin.to_json
    # unwrap and rewrap classmethod to tag it to cls rather than the literal
    # DataClassJsonMixin ABC
    cls.from_json = classmethod(DataClassJsonMixin.from_json.__func__)
    cls.to_dict = DataClassJsonMixin.to_dict
    cls.from_dict = classmethod(DataClassJsonMixin.from_dict.__func__)
    cls.schema = classmethod(DataClassJsonMixin.schema.__func__)

    cls.__init__ = _handle_undefined_parameters_safe(cls, kvs=(), usage="init")
    # register cls as a virtual subclass of DataClassJsonMixin
    DataClassJsonMixin.register(cls)
    return cls 
開發者ID:lidatong,項目名稱:dataclasses-json,代碼行數:20,代碼來源:api.py

示例2: test_class

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def test_class(self):
        self.assertTrue(issubclass(DPMachine, abc.ABC)) 
開發者ID:IBM,項目名稱:differential-privacy-library,代碼行數:4,代碼來源:test_DPMachine.py

示例3: __subclasshook__

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def __subclasshook__(cls, C):
        """Check whether subclass is considered a subclass of this ABC."""
        if cls is AbstractContextManager:
            return _check_methods(C, "__enter__", "__exit__")
        return NotImplemented 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:7,代碼來源:contextlib2.py

示例4: test_ABC_helper

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def test_ABC_helper(self):
        # create an ABC using the helper class and perform basic checks
        class C(abc.ABC):
            @classmethod
            @abc.abstractmethod
            def foo(cls): return cls.__name__
        self.assertEqual(type(C), abc.ABCMeta)
        self.assertRaises(TypeError, C)
        class D(C):
            @classmethod
            def foo(cls): return super().foo()
        self.assertEqual(D.foo(), 'D') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,代碼來源:test_abc.py

示例5: test_non_abstract_children

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def test_non_abstract_children():
    """ check that we can find all constructable children """
    from ctapipe.core import non_abstract_children

    class AbstractBase(ABC):
        @abstractmethod
        def method(self):
            pass

    class Child1(AbstractBase):
        def method(self):
            print("method of Child1")

    class Child2(AbstractBase):
        def method(self):
            print("method of Child2")

    class GrandChild(Child2):
        def method(self):
            print("method of GrandChild")

    class AbstractChild(AbstractBase):
        pass

    kids = non_abstract_children(AbstractBase)
    assert Child1 in kids
    assert Child2 in kids
    assert GrandChild in kids
    assert AbstractChild not in kids 
開發者ID:cta-observatory,項目名稱:ctapipe,代碼行數:31,代碼來源:test_component.py

示例6: __new__

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def __new__(cls, *args, **kwargs):
        new_class = super().__new__(cls, *args, **kwargs)
        # register the class as stat if it does not immediately inherit ABC
        if ABC not in new_class.__bases__:
            new_class._init_tags()
            cls.stat_classes.append(new_class)
        return new_class 
開發者ID:bminixhofer,項目名稱:permon,代碼行數:9,代碼來源:__init__.py

示例7: _RegisterType

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def _RegisterType(type_name):
    """
    Add immutable 'type' field for JSON serialization and connect globals.

    For instance, `class ParamSpecFoo(_RegisterType('foo'), ParamSpec):` means:

    * `_lookup['foo'] == ParamSpecFoo`
    * `ParamSpec.Foo == ParamSpecFoo`
    * ParamSpecFoo(...).type == 'foo'
    """

    @dataclass(frozen=True)
    class ParamSpecType(ABC):
        type: str = field(default=type_name, init=False)

        # override for ABC
        def __init_subclass__(cls, **kwargs):
            name = cls.__name__
            assert name.startswith("ParamSpec")
            subname = name[len("ParamSpec") :]

            super().__init_subclass__(**kwargs)
            _lookup[type_name] = cls
            setattr(ParamSpec, subname, cls)

    return ParamSpecType 
開發者ID:CJWorkbench,項目名稱:cjworkbench,代碼行數:28,代碼來源:param_spec.py

示例8: extract_info

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def extract_info(cls, pyntcloud):
        """ABC API"""
        info = {
            "points": pyntcloud.xyz
        }
        return info 
開發者ID:daavoo,項目名稱:pyntcloud,代碼行數:8,代碼來源:base.py

示例9: get_all_lr_classes

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def get_all_lr_classes():
    """ Get all LR classes defined within this module
    """
    lr_classes = {}
    for name, obj in inspect.getmembers(sys.modules[__name__]):
        if inspect.isclass(obj) and name != 'ABC':
            lr_classes[name] = obj
    return lr_classes 
開發者ID:NVIDIA,項目名稱:NeMo,代碼行數:10,代碼來源:lr_policies.py

示例10: _pick_next

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def _pick_next(self, pair, nodes):
        # avoid ABC error
        raise NotImplementedError() 
開發者ID:andrewcooke,項目名稱:choochoo,代碼行數:5,代碼來源:tree.py

示例11: _pick_seeds

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def _pick_seeds(self, nodes):
        # avoid ABC error
        raise NotImplementedError()

    # _exact_area_sum() is on CartesianMixin because it is not abstracted from the coordinate system. 
開發者ID:andrewcooke,項目名稱:choochoo,代碼行數:7,代碼來源:tree.py

示例12: setName

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def setName(self, name):
        """
        Define name for this expression, makes debugging and exception messages clearer.
        Example::
            Word(nums).parseString("ABC")  # -> Exception: Expected W:(0-9) (at char 0), (line:1, col:1)
            Word(nums).setName("integer").parseString("ABC")  # -> Exception: Expected integer (at char 0), (line:1, col:1)
        """
        self.customName = name
        self.errmsg = "Expected " + self.name
        if __diag__.enable_debug_on_named_expressions:
            self.setDebug()
        return self 
開發者ID:pyparsing,項目名稱:pyparsing,代碼行數:14,代碼來源:core.py

示例13: test_model_subclassing_abstract_base_classes

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def test_model_subclassing_abstract_base_classes():
    class Model(BaseModel, abc.ABC):
        some_field: str 
開發者ID:samuelcolvin,項目名稱:pydantic,代碼行數:5,代碼來源:test_abc.py

示例14: test_model_subclassing_abstract_base_classes_without_implementation_raises_exception

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def test_model_subclassing_abstract_base_classes_without_implementation_raises_exception():
    class Model(BaseModel, abc.ABC):
        some_field: str

        @abc.abstractmethod
        def my_abstract_method(self):
            pass

        @classmethod
        @abc.abstractmethod
        def my_abstract_classmethod(cls):
            pass

        @staticmethod
        @abc.abstractmethod
        def my_abstract_staticmethod():
            pass

        @property
        @abc.abstractmethod
        def my_abstract_property(self):
            pass

        @my_abstract_property.setter
        @abc.abstractmethod
        def my_abstract_property(self, val):
            pass

    with pytest.raises(TypeError) as excinfo:
        Model(some_field='some_value')
    assert str(excinfo.value) == (
        "Can't instantiate abstract class Model with abstract methods "
        "my_abstract_classmethod, my_abstract_method, my_abstract_property, my_abstract_staticmethod"  # noqa: Q000
    ) 
開發者ID:samuelcolvin,項目名稱:pydantic,代碼行數:36,代碼來源:test_abc.py

示例15: should

# 需要導入模塊: import abc [as 別名]
# 或者: from abc import ABC [as 別名]
def should(self, condition: Condition[E]) -> E:
        pass


# todo: try as Matchable(ABC) and check if autocomplete will still work 
開發者ID:yashaka,項目名稱:selene,代碼行數:7,代碼來源:entity.py


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