summaryrefslogtreecommitdiff
path: root/tests/functional/p/positional_only_arguments_expected.py
blob: 98a2d65f5cf155cd60b3ae99c36c94c358384567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# pylint: disable=missing-docstring,unused-argument,pointless-statement
# pylint: disable=too-few-public-methods

class Gateaux:
    def nihon(self, a, r, i, /, cheese=False):
        return f"{a}{r}{i}gateaux" + " au fromage" if cheese else ""


cake = Gateaux()
# Should not emit error
cake.nihon(1, 2, 3)
cake.nihon(1, 2, 3, True)
cake.nihon(1, 2, 3, cheese=True)
# Emits error
cake.nihon(1, 2, i=3)  # [positional-only-arguments-expected]
cake.nihon(1, r=2, i=3)  # [positional-only-arguments-expected]
cake.nihon(a=1, r=2, i=3)  # [positional-only-arguments-expected]
cake.nihon(1, r=2, i=3, cheese=True)  # [positional-only-arguments-expected]


def function_with_kwargs(apple, banana="Yellow banana", /, **kwargs):
    """
    Calling this function with the `banana` keyword should not emit
    `positional-only-arguments-expected` since it is added to `**kwargs`.

    >>> function_with_kwargs("Red apple", banana="Green banana")
    >>> "Red apple"
    >>> "Yellow banana"
    >>> {"banana": "Green banana"}
    """
    print(apple)
    print(banana)
    print(kwargs)


function_with_kwargs("Red apple", banana="Green banana")