Repository: pallets/click

Issue:
Use flake8 4.0.x
As discussed [here](https://github.com/pallets/click/pull/1896#discussion_r632668344), `flake8` did not properly detect imports of the `typing` module when aliased like `import typing as t`, which is a pattern used in this repository. Detection of `typing` is needed for `flake8` to understand (and ignore with respect to F811) function redefinitions using the `@typing.overload` decorator, so where this decorator is used, `click` imports the module twice:

```python
import typing
import typing as t
```

With PyCQA/pyflakes#632 merged, `pyflakes` 2.4.0 properly detects aliased `typing` imports, and `flake8` 4.0.x uses `pyflakes >= 2.4.0, < 2.5.0`. If we upgrade to using this newer version of `flake8`, we can remove the duplicate imports.

As far as I can tell it's as simple as changing one line in `.pre-commit-config.yaml`, but I'm not sure if there's more needed under the hood to update the CI pipeline. I'm ready to open a PR for this if people agree on the update.


Discussion:

Resolving patch:
diff --git a/src/click/core.py b/src/click/core.py
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -2,7 +2,6 @@
 import errno
 import os
 import sys
-import typing
 import typing as t
 from collections import abc
 from contextlib import contextmanager
@@ -632,13 +631,13 @@ def ensure_object(self, object_type: t.Type[V]) -> V:
             self.obj = rv = object_type()
         return rv
 
-    @typing.overload
+    @t.overload
     def lookup_default(
         self, name: str, call: "te.Literal[True]" = True
     ) -> t.Optional[t.Any]:
         ...
 
-    @typing.overload
+    @t.overload
     def lookup_default(
         self, name: str, call: "te.Literal[False]" = ...
     ) -> t.Optional[t.Union[t.Any, t.Callable[[], t.Any]]]:
@@ -956,7 +955,7 @@ def shell_complete(self, ctx: Context, incomplete: str) -> t.List["CompletionIte
 
         return results
 
-    @typing.overload
+    @t.overload
     def main(
         self,
         args: t.Optional[t.Sequence[str]] = None,
@@ -967,7 +966,7 @@ def main(
     ) -> "te.NoReturn":
         ...
 
-    @typing.overload
+    @t.overload
     def main(
         self,
         args: t.Optional[t.Sequence[str]] = None,
@@ -2172,13 +2171,13 @@ def make_metavar(self) -> str:
 
         return metavar
 
-    @typing.overload
+    @t.overload
     def get_default(
         self, ctx: Context, call: "te.Literal[True]" = True
     ) -> t.Optional[t.Any]:
         ...
 
-    @typing.overload
+    @t.overload
     def get_default(
         self, ctx: Context, call: bool = ...
     ) -> t.Optional[t.Union[t.Any, t.Callable[[], t.Any]]]:
@@ -2753,13 +2752,13 @@ def _write_opts(opts: t.Sequence[str]) -> str:
 
         return ("; " if any_prefix_is_slash else " / ").join(rv), help
 
-    @typing.overload
+    @t.overload
     def get_default(
         self, ctx: Context, call: "te.Literal[True]" = True
     ) -> t.Optional[t.Any]:
         ...
 
-    @typing.overload
+    @t.overload
     def get_default(
         self, ctx: Context, call: bool = ...
     ) -> t.Optional[t.Union[t.Any, t.Callable[[], t.Any]]]:
diff --git a/src/click/globals.py b/src/click/globals.py
--- a/src/click/globals.py
+++ b/src/click/globals.py
@@ -1,4 +1,3 @@
-import typing
 import typing as t
 from threading import local
 
@@ -9,12 +8,12 @@
 _local = local()
 
 
-@typing.overload
+@t.overload
 def get_current_context(silent: "te.Literal[False]" = False) -> "Context":
     ...
 
 
-@typing.overload
+@t.overload
 def get_current_context(silent: bool = ...) -> t.Optional["Context"]:
     ...
 
diff --git a/src/click/termui.py b/src/click/termui.py
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -3,7 +3,6 @@
 import itertools
 import os
 import sys
-import typing
 import typing as t
 from gettext import gettext as _
 


Test patch: