当前位置: 首页>>代码示例>>Python>>正文


Python utils.with_metaclass方法代码示例

本文整理汇总了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 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:13,代码来源:test_list.py

示例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 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:13,代码来源:test_bytes.py

示例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 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:13,代码来源:test_object.py

示例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 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:13,代码来源:test_dict.py

示例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 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:13,代码来源:test_int.py

示例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) 
开发者ID:hearsaycorp,项目名称:normalize,代码行数:29,代码来源:test_types.py

示例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 
开发者ID:threeML,项目名称:astromodels,代码行数:40,代码来源:test_functions.py


注:本文中的future.utils.with_metaclass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。