def test_defaults_evaluated_in_defining_scope(self):
        source = """
def f():
    def g(x=x):
        pass
x = 1
"""

        node = ast_utils.parse(source, "__test__")
        results = analyze_closures(node)

        assert 'x' in get_results(results, 'f').from_global
        assert 'x' not in get_results(results, 'g').from_global
예제 #2
0
    def test_defaults_evaluated_in_defining_scope(self):
        source = """
def f():
    def g(x=x):
        pass
x = 1
"""

        node = ast_utils.parse(source, "__test__")
        results = analyze_closures(node)

        assert 'x' in get_results(results, 'f').from_global
        assert 'x' not in get_results(results, 'g').from_global
    def test_checks_dynamic_defaults(self):
        source = """
def f(x=1):
    pass
y = 2
def g(y=y):
    pass
def h():
    f, g
"""

        node = ast_utils.parse(source, "__test__")
        results = analyze_closures(node)

        module = get_results(results, "<module>")
        assert "f" in module.functions
        assert "f" not in module.used_in_nested
        assert "g" not in module.functions
        assert "g" in module.used_in_nested
예제 #4
0
    def test_checks_dynamic_defaults(self):
        source = """
def f(x=1):
    pass
y = 2
def g(y=y):
    pass
def h():
    f, g
"""

        node = ast_utils.parse(source, "__test__")
        results = analyze_closures(node)

        module = get_results(results, "<module>")
        assert "f" in module.functions
        assert "f" not in module.used_in_nested
        assert "g" not in module.functions
        assert "g" in module.used_in_nested