summaryrefslogtreecommitdiff
path: root/tests/functional/r/regression_02/regression_4660.py
blob: b3dee058f55efb4e57b16aaff7eefd5df9a29e2e (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
37
38
39
40
41
42
43
44
45
"""Regression tests for https://github.com/pylint-dev/pylint/issues/4660"""

# pylint: disable=useless-return, unused-argument
# pylint: disable=missing-docstring, too-few-public-methods, invalid-name

from __future__ import annotations

from typing import Union, Any, Literal, overload
from collections.abc import Callable


def my_print(*args: Any) -> None:
    print(", ".join(str(x) for x in args))
    return


# ---- This is OK ----
class MyClass:
    def my_method(self, option: Literal["mandatory"]) -> Callable[..., Any]:
        return my_print


c = MyClass().my_method("mandatory")
c(1, "foo")

# ---- This runs OK but pylint reports an error ----
class MyClass1:
    @overload
    def my_method(self, option: Literal["mandatory"]) -> Callable[..., Any]:
        ...

    @overload
    def my_method(
        self, option: Literal["optional", "mandatory"]
    ) -> Union[None, Callable[..., Any]]:
        ...

    def my_method(
        self, option: Literal["optional", "mandatory"]
    ) -> Union[None, Callable[..., Any]]:
        return my_print


d = MyClass1().my_method("mandatory")
d(1, "bar")  # [not-callable]