本文整理汇总了Python中nope.couscous.ref函数的典型用法代码示例。如果您正苦于以下问题:Python ref函数的具体用法?Python ref怎么用?Python ref使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ref函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_method_is_called_if_present
def init_method_is_called_if_present(self):
node = cc.class_("A", methods=[
cc.func("__init__", [cc.arg("self"), cc.arg("value")], [
cc.expression_statement(cc.call(cc.ref("print"), [cc.ref("value")]))
])
], body=[])
expected_aux = """internal class __A {
internal dynamic __init__;
}
"""
expected = """A = new
{
__call__ = ((System.Func<dynamic, dynamic>)((dynamic __value) =>
{
dynamic __self = null;
__self = new __A {
__init__ = ((System.Func<dynamic, dynamic>)((dynamic value) =>
{
dynamic self = __self;
print(value);
})),
};
__self.__init__(__value);
return __self;
})),
};
"""
transformer = _create_transformer()
assert_equal(expected, cs.dumps(transformer.transform(node)))
assert_equal(expected_aux, cs.dumps(transformer.aux()))
示例2: test_transform_try_except_with_multiple_exception_handlers
def test_transform_try_except_with_multiple_exception_handlers():
_assert_transform(
cc.try_(
[cc.ret(cc.ref("x"))],
handlers=[
cc.except_(cc.ref("AssertionError"), None, [cc.ret(cc.ref("y"))]),
cc.except_(cc.ref("Exception"), None, [cc.ret(cc.ref("z"))]),
],
),
"""
try {
return x;
} catch ($exception0) {
if ($exception0.$nopeException === $nope.undefined) {
throw $exception0;
} else {
if ($nope.builtins.isinstance($exception0.$nopeException, AssertionError)) {
return y;
} else {
if ($nope.builtins.isinstance($exception0.$nopeException, Exception)) {
return z;
} else {
throw $exception0;
}
}
}
}
""",
)
示例3: test_transform_raise_without_exception_value
def test_transform_raise_without_exception_value():
_assert_transform(
cc.try_(
[cc.ret(cc.ref("x"))],
handlers=[
cc.except_(cc.ref("AssertionError"), cc.ref("error"), [cc.raise_()]),
],
),
"""
try {
return x;
} catch ($exception0) {
if ($exception0.$nopeException === $nope.undefined) {
throw $exception0;
} else {
if ($nope.builtins.isinstance($exception0.$nopeException, AssertionError)) {
var error = $exception0.$nopeException;
throw $exception0;
} else {
throw $exception0;
}
}
}
""",
)
示例4: test_transform_compound_assignments
def test_transform_compound_assignments(self):
_assert_transform(
nodes.assign(["x", "y"], nodes.ref("z")),
cc.statements([
cc.declare("__nope_u_tmp0", cc.ref("z")),
cc.assign(cc.ref("x"), cc.ref("__nope_u_tmp0")),
cc.assign(cc.ref("y"), cc.ref("__nope_u_tmp0")),
]),
)
示例5: test_transform_boolean_or
def test_transform_boolean_or(self):
_assert_transform(
nodes.bool_or(nodes.ref("x"), nodes.ref("y")),
cc.ternary_conditional(
cc.call(cc.builtin("bool"), [cc.ref("x")]),
cc.ref("x"),
cc.ref("y")
),
)
示例6: test_transform_call_with_positional_arguments
def test_transform_call_with_positional_arguments(self):
func_node = nodes.ref("f")
type_lookup = [
(func_node, types.func([types.str_type], types.none_type))
]
_assert_transform(
nodes.call(func_node, [nodes.ref("x")]),
cc.call(cc.ref("f"), [cc.ref("x")]),
type_lookup=type_lookup,
)
示例7: test_import_of_module_in_package_assigns_values_for_both_package_and_module
def test_import_of_module_in_package_assigns_values_for_both_package_and_module(self):
_assert_transform(
nodes.import_([
nodes.import_alias("os.path", None),
]),
cc.statements([
cc.assign(cc.ref("os"), cc.module_ref(["os"])),
cc.assign(cc.attr(cc.ref("os"), "path"), cc.module_ref(["os", "path"])),
])
)
示例8: test_transform_while_loop
def test_transform_while_loop(self):
_assert_transform(
nodes.while_(
nodes.ref("x"),
[nodes.ret(nodes.ref("y"))],
),
cc.while_(
cc.call(cc.builtin("bool"), [cc.ref("x")]),
[cc.ret(cc.ref("y"))],
)
)
示例9: test_multiple_imported_names_in_one_statement_generates_multiple_assignments
def test_multiple_imported_names_in_one_statement_generates_multiple_assignments(self):
_assert_transform(
nodes.import_from(["."], [
nodes.import_alias("x", None),
nodes.import_alias("y", None),
]),
cc.statements([
cc.assign(cc.ref("x"), cc.attr(cc.module_ref(["."]), "x")),
cc.assign(cc.ref("y"), cc.attr(cc.module_ref(["."]), "y")),
]),
)
示例10: test_import_multiple_values_in_single_import_statement
def test_import_multiple_values_in_single_import_statement(self):
_assert_transform(
nodes.import_([
nodes.import_alias("os", None),
nodes.import_alias("sys", None)
]),
cc.statements([
cc.assign(cc.ref("os"), cc.module_ref(["os"])),
cc.assign(cc.ref("sys"), cc.module_ref(["sys"])),
])
)
示例11: test_transform_while_loop
def test_transform_while_loop():
_assert_transform(
cc.while_(
cc.ref("x"),
[cc.ret(cc.ref("y"))],
),
js.while_(
js.ref("x"),
[js.ret(js.ref("y"))],
)
)
示例12: test_variables_are_declared
def test_variables_are_declared(self):
_assert_transform(
nodes.func("f", nodes.args([]), [
nodes.assign([nodes.ref("x")], nodes.ref("y")),
nodes.ret(nodes.ref("value")),
], type=None),
cc.func("f", [], [
cc.declare("x"),
cc.assign(cc.ref("x"), cc.ref("y")),
cc.ret(cc.ref("value")),
]),
)
示例13: test_transform_if_else
def test_transform_if_else():
_assert_transform(
cc.if_(
cc.ref("x"),
[cc.ret(cc.ref("y"))],
[cc.ret(cc.ref("z"))],
),
js.if_(
js.ref("x"),
[js.ret(js.ref("y"))],
[js.ret(js.ref("z"))],
)
)
示例14: try_with_finally_is_converted_to_try_with_finally
def try_with_finally_is_converted_to_try_with_finally(self):
node = cc.try_(
[cc.ret(cc.ref("x"))],
finally_body=[cc.expression_statement(cc.ref("y"))]
)
expected = """try {
return x;
} finally {
y;
}
"""
assert_equal(expected, cs.dumps(transform(node)))
示例15: test_statements_in_bodies_are_transformed
def test_statements_in_bodies_are_transformed(self):
_assert_transform(
nodes.try_(
[nodes.ret(nodes.ref("x"))],
handlers=[nodes.except_(nodes.ref("Exception"), nodes.ref("error"), [nodes.ref("y")])],
finally_body=[nodes.ret(nodes.ref("z"))],
),
cc.try_(
[cc.ret(cc.ref("x"))],
handlers=[cc.except_(cc.ref("Exception"), cc.ref("error"), [cc.ref("y")])],
finally_body=[cc.ret(cc.ref("z"))],
),
)