summaryrefslogtreecommitdiff
path: root/pylint/test/functional/unused_typing_imports.py
blob: 6edca7153820a66d4622bbe8b1a8580e99cc15e0 (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
46
47
48
49
50
51
52
53
54
55
56
# pylint: disable=missing-docstring, bad-whitespace
"""Regression test for https://github.com/PyCQA/pylint/issues/1168

The problem was that we weren't handling keyword-only arguments annotations,
which means we were never processing them.
"""

import re
import typing
from typing import (
    Any,
    Callable,
    Iterable,
    List,
    NamedTuple,
    Optional,
    Pattern,
    Set,
    Tuple,
)


def func1(arg: Optional[Callable]=None):
    return arg


def func2(*, arg: Optional[Iterable]=None):
    return arg


SOME_VALUE = [1] # type: List[Any]
for VALUE in [[1], [2], [3]]:  # type: Tuple[Any]
    print(VALUE)


class ContextManager:
    def __enter__(self):
        return {1}

    def __exit__(self, *_args):
        pass


with ContextManager() as SOME_DICT: # type: Set[int]
    print(SOME_DICT)


def func_test_type_comment(param):
    # type: (NamedTuple) -> Tuple[NamedTuple, Pattern]
    return param, re.compile('good')


def typing_fully_qualified():
    variable = None  # type: typing.Optional[str]
    other_variable: 'typing.Optional[str]' = None
    return variable, other_variable