예제 #1
0
def test_varnames_keyword_only() -> None:
    def f1(x, *, y) -> None:
        pass

    def f2(x, *, y=3) -> None:
        pass

    def f3(x=1, *, y=3) -> None:
        pass

    assert varnames(f1) == (("x", ), ())
    assert varnames(f2) == (("x", ), ())
    assert varnames(f3) == ((), ("x", ))
예제 #2
0
def test_varnames() -> None:
    def f(x) -> None:
        i = 3  # noqa

    class A:
        def f(self, y) -> None:
            pass

    class B:
        def __call__(self, z) -> None:
            pass

    assert varnames(f) == (("x", ), ())
    assert varnames(A().f) == (("y", ), ())
    assert varnames(B()) == (("z", ), ())
예제 #3
0
def test_varnames_class() -> None:
    class C:
        def __init__(self, x) -> None:
            pass

    class D:
        pass

    class E:
        def __init__(self, x) -> None:
            pass

    class F:
        pass

    assert varnames(C) == (("x", ), ())
    assert varnames(D) == ((), ())
    assert varnames(E) == (("x", ), ())
    assert varnames(F) == ((), ())
예제 #4
0
def test_varnames_default() -> None:
    def f(x, y=3) -> None:
        pass

    assert varnames(f) == (("x", ), ("y", ))