本文整理汇总了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
示例2: test_class
# 需要导入模块: import abc [as 别名]
# 或者: from abc import ABC [as 别名]
def test_class(self):
self.assertTrue(issubclass(DPMachine, abc.ABC))
示例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
示例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')
示例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
示例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
示例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
示例8: extract_info
# 需要导入模块: import abc [as 别名]
# 或者: from abc import ABC [as 别名]
def extract_info(cls, pyntcloud):
"""ABC API"""
info = {
"points": pyntcloud.xyz
}
return info
示例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
示例10: _pick_next
# 需要导入模块: import abc [as 别名]
# 或者: from abc import ABC [as 别名]
def _pick_next(self, pair, nodes):
# avoid ABC error
raise NotImplementedError()
示例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.
示例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
示例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
示例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
)
示例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