本文整理汇总了Python中future.utils.with_metaclass方法的典型用法代码示例。如果您正苦于以下问题:Python utils.with_metaclass方法的具体用法?Python utils.with_metaclass怎么用?Python utils.with_metaclass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类future.utils
的用法示例。
在下文中一共展示了utils.with_metaclass方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_with_metaclass_and_list
# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import with_metaclass [as 别名]
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
示例2: test_with_metaclass_and_bytes
# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import with_metaclass [as 别名]
def test_with_metaclass_and_bytes(self):
"""
Issue #91 (for newdict instead of newobject)
"""
from future.utils import with_metaclass
class MetaClass(type):
pass
class TestClass(with_metaclass(MetaClass, bytes)):
pass
示例3: test_with_metaclass_and_object
# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import with_metaclass [as 别名]
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
示例4: test_with_metaclass_and_dict
# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import with_metaclass [as 别名]
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
示例5: test_with_metaclass_and_int
# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import with_metaclass [as 别名]
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
示例6: test_subtype_abstract
# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import with_metaclass [as 别名]
def test_subtype_abstract(self):
import abc
class AbstractClass(with_metaclass(abc.ABCMeta, object)):
@abc.abstractmethod
def define_me(self):
pass
SubAbstractClass = subtype(
of=AbstractClass,
name="SubAbstractClass",
where=lambda v: v.define_me() > 0
)
self.assertEqual(
str(SubAbstractClass),
"<ABCMetaSubtype SubAbstractClass of AbstractClass>",
)
class ConcreteClass(AbstractClass):
def __init__(self, what):
self.what = what
def define_me(self):
return self.what
self.assertIsInstance(ConcreteClass(1), SubAbstractClass)
self.assertNotIsInstance(ConcreteClass(-1), SubAbstractClass)
示例7: get_a_function_class
# 需要导入模块: from future import utils [as 别名]
# 或者: from future.utils import with_metaclass [as 别名]
def get_a_function_class():
# Try to create a function inheriting from Function with meta FunctionMeta
class Test_function(with_metaclass(FunctionMeta, Function1D)):
r"""
description :
A test function
latex : $ a * x + b $
parameters :
a :
desc : linear coefficient
initial value : 1
b :
desc : intercept
initial value : 1
"""
def _set_units(self, x_unit, y_unit):
# a has units of y_unit / x_unit, so that a*x has units of y_unit
self.a.unit = y_unit / x_unit
# b has units of y
self.b.unit = y_unit
def evaluate(self, x, a, b):
return a * x + b
return Test_function