• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python module.module函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nitrous.module.module函数的典型用法代码示例。如果您正苦于以下问题:Python module函数的具体用法?Python module怎么用?Python module使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了module函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_branch_elimination

    def test_branch_elimination(self):
        from nitrous.module import dump

        add_5 = False
        add_any = True

        @function(Long, a=Long, b=Bool)
        def f1(a, b):
            if add_any and b:
                a += 5
            return a

        @function(Long, a=Long)
        def f2(a):
            if add_any and add_5:
                a += 5
            return a

        m1 = module([f1])
        ir = " ".join(dump(m1).split("\n"))
        # In first function, conditional depends on a parameter
        self.assertRegexpMatches(ir, "icmp")

        m2 = module([f2])
        ir = " ".join(dump(m2).split("\n"))
        # In second, entire conditional is resolved at
        # compile time and optimized away
        self.assertNotRegexpMatches(ir, "icmp")
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:28,代码来源:test_basic.py


示例2: test_not_iterable

    def test_not_iterable(self):

        @function(a=Long)
        def foo(a):
            b, = a

        message = "Value of type 'Long' is not an iterable"
        with self.assertRaisesRegexp(TypeError, message):
            module([foo])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:9,代码来源:test_basic.py


示例3: test_type_mismatch

    def test_type_mismatch(self):

        @function(Bool, x=Long)
        def f1(x):
            return x < 1.0

        message = ">>>     return x < 1.0"
        with self.assertRaisesRegexp(TypeError, message):
            module([f1])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:9,代码来源:test_basic.py


示例4: test_assign_wrong_type

    def test_assign_wrong_type(self):

        @function(x=Array(Long, shape=(1,)), y=Double)
        def f(x, y):
            x[0] = y

        message = ">>>     x\[0\] = y"
        with self.assertRaisesRegexp(TypeError, message):
            module([f])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:9,代码来源:test_basic.py


示例5: test_compound_test

    def test_compound_test(self):
        """Support compound conditionals such as 1 < x < 2."""

        @function(Bool, x=Long)
        def f1(x):
            return 1 < x < 2

        message = ">>>     return 1 < x < 2"
        with self.assertRaisesRegexp(NotImplementedError, message):
            module([f1])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:10,代码来源:test_basic.py


示例6: test_unexpected_type

    def test_unexpected_type(self):
        """Raise error if returning unexpected value type."""

        @function(Double, x=Double)
        def f(x):
            return 5

        message = ">>>     return 5"
        with self.assertRaisesRegexp(TypeError, message):
            module([f])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:10,代码来源:test_basic.py


示例7: test_missing_return

    def test_missing_return(self):
        """Raise error if no return in function with non-void return type."""

        @function(Double)
        def f():
            pass

        message = ">>>     pass"
        with self.assertRaisesRegexp(TypeError, message):
            module([f])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:10,代码来源:test_basic.py


示例8: test_shape_mismatch

    def test_shape_mismatch(self):
        """Raise error if packed/unpacked tuple lengths differ"""

        @function(Long, a=Long, b=Long)
        def foo(a, b):
            b, = a, b

        message = "Cannot unpack 2 values into 1"
        with self.assertRaisesRegexp(ValueError, message):
            module([foo])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:10,代码来源:test_basic.py


示例9: test_missing_symbol

    def test_missing_symbol(self):
        """Raise error if cannot resolve a symbol."""

        @function(Double, y=Long)
        def x(y):
            return z

        error = ">>>     return z"
        with self.assertRaisesRegexp(NameError, error):
            module([x])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:10,代码来源:test_basic.py


示例10: test_return_non_void

    def test_return_non_void(self):
        """Raise error if void function returns non-void value"""

        @function()
        def f():
            return 5

        message = ">>>     return 5"
        with self.assertRaisesRegexp(ValueError, message):
            module([f])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:10,代码来源:test_basic.py


示例11: test_unsupported_slice

    def test_unsupported_slice(self):
        """Raise error on unsupported context (eg. `del x`)."""

        @function(Long, y=Long)
        def x(y):
            y[:]
            return 0

        message = ">>>     y\[:\]"
        with self.assertRaisesRegexp(NotImplementedError, message):
            module([x])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:11,代码来源:test_basic.py


示例12: test_unsupported_target

    def test_unsupported_target(self):
        """Check for unsupported assignments."""

        @function(Long, a=Long, b=Long)
        def f(a, b):
            a, b = 1
            return 0

        message = ">>>     a, b = 1"
        with self.assertRaisesRegexp(TypeError, message):
            module([f])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:11,代码来源:test_basic.py


示例13: test_unsupported_chain

    def test_unsupported_chain(self):
        """Raise error on chain assignment."""

        @function(Long)
        def f():
            a = b = 1
            return 0

        message = ">>>     a = b = 1"
        with self.assertRaisesRegexp(NotImplementedError, message):
            module([f])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:11,代码来源:test_basic.py


示例14: test_if_expr_type_mismatch

    def test_if_expr_type_mismatch(self):
        """Raise error when `if` expression clause types don't match."""

        # Simple expression
        @function(Long, a=Long, b=Long)
        def max2(a, b):
            return 1.0 if a > b else 0

        message = ">>>     return 1.0 if a > b else 0"
        with self.assertRaisesRegexp(TypeError, message):
            module([max2])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:11,代码来源:test_basic.py


示例15: test_symbol_out_of_scope

    def test_symbol_out_of_scope(self):
        """Raise error if symbol is available but not in the current scope."""

        @function(Double, y=Long)
        def x(y):
            for i in range(y):
                z = i
            return z

        error = ">>>     return z"
        with self.assertRaisesRegexp(NameError, error):
            module([x])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:12,代码来源:test_basic.py


示例16: test_unsupported_context

    def test_unsupported_context(self):
        """Raise error on unsupported context (eg. `del x`)."""

        @function(Long)
        def x():
            y = 1
            del y
            return 0

        message = ">>>     del y"
        with self.assertRaisesRegexp(NotImplementedError, message):
            module([x])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:12,代码来源:test_basic.py


示例17: test_invalid_cast

    def test_invalid_cast(self):
        from nitrous.lib import cast
        from nitrous.types import Structure

        S = Structure("S", ("x", Long))

        @function(Long, a=S)
        def int_to_long(a):
            return cast(a, Long)

        with self.assertRaisesRegexp(TypeError, "Cannot cast"):
            module([int_to_long])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:12,代码来源:test_lib.py


示例18: test_call_wrong_arg_type

    def test_call_wrong_arg_type(self):

        @function(Long, x=Long)
        def f1(x):
            return x

        @function(Long, x=Long)
        def f2(x):
            return f1(1.0)

        message = "f1\(\) called with wrong argument type\(s\) for x"
        with self.assertRaisesRegexp(TypeError, message):
            module([f2])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:13,代码来源:test_basic.py


示例19: test_call_wrong_arg_count

    def test_call_wrong_arg_count(self):

        @function(Long, x=Long)
        def f1(x):
            return x

        @function(Long, x=Long)
        def f2(x):
            return f1(x, 1)

        message = "f1\(\) takes exactly 1 argument\(s\) \(2 given\)"
        with self.assertRaisesRegexp(TypeError, message):
            module([f2])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:13,代码来源:test_basic.py


示例20: test_duplicate_function

    def test_duplicate_function(self):

        def get_foo():

            @function(Long, a=Long)
            def foo(a):
                return 1

            return foo

        message = "Duplicate function name: foo"
        with self.assertRaisesRegexp(RuntimeError, message):
            module([get_foo(), get_foo()])
开发者ID:dtcaciuc,项目名称:nitrous,代码行数:13,代码来源:test_module.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python i18n._函数代码示例发布时间:2022-05-27
下一篇:
Python log.info函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap