当前位置: 首页>>代码示例>>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;未经允许,请勿转载。