當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。