From 64a610ed19beb3a9b50c7ae83d1ae861fc6613ef Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 29 Mar 2021 19:33:44 -0700 Subject: [PATCH] clean up TYPE_CHECKING imports --- .coveragerc | 1 + src/flake8/__init__.py | 4 +--- src/flake8/formatting/base.py | 3 ++- src/flake8/formatting/default.py | 3 ++- src/flake8/main/application.py | 6 +++--- src/flake8/options/manager.py | 6 ++++-- src/flake8/statistics.py | 3 ++- src/flake8/utils.py | 3 ++- 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.coveragerc b/.coveragerc index 7d2dd68..d1b8806 100644 --- a/.coveragerc +++ b/.coveragerc @@ -30,3 +30,4 @@ exclude_lines = # Don't complain if non-runnable code isn't run: ^if __name__ == ['"]__main__['"]:$ ^\s*if False: + ^\s*if TYPE_CHECKING: diff --git a/src/flake8/__init__.py b/src/flake8/__init__.py index ea2f541..a6f2b62 100644 --- a/src/flake8/__init__.py +++ b/src/flake8/__init__.py @@ -11,9 +11,7 @@ This module """ import logging import sys - -if False: # `typing.TYPE_CHECKING` was introduced in 3.5.2 - from typing import Type # `typing.Type` was introduced in 3.5.2 +from typing import Type LOG = logging.getLogger(__name__) LOG.addHandler(logging.NullHandler()) diff --git a/src/flake8/formatting/base.py b/src/flake8/formatting/base.py index 89789b5..d98b290 100644 --- a/src/flake8/formatting/base.py +++ b/src/flake8/formatting/base.py @@ -4,8 +4,9 @@ from typing import IO from typing import List from typing import Optional from typing import Tuple +from typing import TYPE_CHECKING -if False: # `typing.TYPE_CHECKING` was introduced in 3.5.2 +if TYPE_CHECKING: from flake8.statistics import Statistics from flake8.style_guide import Violation diff --git a/src/flake8/formatting/default.py b/src/flake8/formatting/default.py index 0ff5a9b..dc78254 100644 --- a/src/flake8/formatting/default.py +++ b/src/flake8/formatting/default.py @@ -1,10 +1,11 @@ """Default formatting class for Flake8.""" from typing import Optional from typing import Set +from typing import TYPE_CHECKING from flake8.formatting import base -if False: # `typing.TYPE_CHECKING` was introduced in 3.5.2 +if TYPE_CHECKING: from flake8.style_guide import Violation diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index f5e3f10..fb23db5 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -8,6 +8,8 @@ from typing import List from typing import Optional from typing import Set from typing import Tuple +from typing import Type +from typing import TYPE_CHECKING import flake8 from flake8 import checker @@ -21,9 +23,7 @@ from flake8.options import config from flake8.options import manager from flake8.plugins import manager as plugin_manager -if False: # `typing.TYPE_CHECKING` was introduced in 3.5.2 - from typing import Type # `typing.Type` was introduced in 3.5.2 - +if TYPE_CHECKING: from flake8.formatting.base import BaseFormatter diff --git a/src/flake8/options/manager.py b/src/flake8/options/manager.py index f537a42..206094f 100644 --- a/src/flake8/options/manager.py +++ b/src/flake8/options/manager.py @@ -16,12 +16,14 @@ from typing import Optional from typing import Sequence from typing import Set from typing import Tuple +from typing import Type +from typing import TYPE_CHECKING from typing import Union from flake8 import utils -if False: # TYPE_CHECKING - from typing import NoReturn, Type +if TYPE_CHECKING: + from typing import NoReturn LOG = logging.getLogger(__name__) diff --git a/src/flake8/statistics.py b/src/flake8/statistics.py index c238b8d..0ccc746 100644 --- a/src/flake8/statistics.py +++ b/src/flake8/statistics.py @@ -4,8 +4,9 @@ from typing import Dict from typing import Generator from typing import List from typing import Optional +from typing import TYPE_CHECKING -if False: # `typing.TYPE_CHECKING` was introduced in 3.5.2 +if TYPE_CHECKING: from flake8.style_guide import Violation diff --git a/src/flake8/utils.py b/src/flake8/utils.py index d461bb5..aec5a43 100644 --- a/src/flake8/utils.py +++ b/src/flake8/utils.py @@ -19,11 +19,12 @@ from typing import Pattern from typing import Sequence from typing import Set from typing import Tuple +from typing import TYPE_CHECKING from typing import Union from flake8 import exceptions -if False: # `typing.TYPE_CHECKING` was introduced in 3.5.2 +if TYPE_CHECKING: from flake8.plugins.manager import Plugin DIFF_HUNK_REGEXP = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$")