本文整理匯總了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