summaryrefslogtreecommitdiff
path: root/tests/functional/u/unused/unused_typing_imports.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional/u/unused/unused_typing_imports.py')
-rw-r--r--tests/functional/u/unused/unused_typing_imports.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/functional/u/unused/unused_typing_imports.py b/tests/functional/u/unused/unused_typing_imports.py
new file mode 100644
index 000000000..7de4e411b
--- /dev/null
+++ b/tests/functional/u/unused/unused_typing_imports.py
@@ -0,0 +1,85 @@
+# pylint: disable=missing-docstring
+"""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 collections import Counter as CollectionCounter
+from collections import defaultdict
+from datetime import datetime
+from typing import (
+ Any,
+ Callable,
+ Iterable,
+ List,
+ NamedTuple,
+ Optional,
+ Pattern,
+ Sequence,
+ 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
+
+
+def function(arg1, # type: Iterable
+ arg2 # type: List
+ ):
+ # type: (...) -> Sequence
+ """docstring"""
+ print(arg1, arg2)
+
+
+def magic(alpha, beta, gamma):
+ # type: (str, Optional[str], Optional[datetime]) -> Any
+ """going strong"""
+ return alpha, beta, gamma
+
+
+def unused_assignment_import():
+ foo_or_bar = 42 # type: defaultdict
+ return foo_or_bar
+
+
+def unused_reassigned_import(counter):
+ # type: (CollectionCounter) -> int
+ print(counter)
+ return 42