Skip to content

Commit 0b202aa

Browse files
committed
Move typechecking imports under TYPE_CHECKING flag
1 parent 88e4bc6 commit 0b202aa

File tree

102 files changed

+692
-390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+692
-390
lines changed

pylint/checkers/bad_chained_comparison.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
from typing import TYPE_CHECKING
88

9-
from astroid import nodes
10-
119
from pylint.checkers import BaseChecker
1210
from pylint.interfaces import HIGH
1311

1412
if TYPE_CHECKING:
13+
from astroid import nodes
14+
1515
from pylint.lint import PyLinter
1616

1717
COMPARISON_OP = frozenset(("<", "<=", ">", ">=", "!=", "=="))

pylint/checkers/base/basic_checker.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88

99
import collections
1010
import itertools
11-
from collections.abc import Iterator
1211
from typing import TYPE_CHECKING, Literal, cast
1312

1413
import astroid
1514
from astroid import nodes, objects, util
1615

1716
from pylint import utils as lint_utils
1817
from pylint.checkers import BaseChecker, utils
19-
from pylint.interfaces import HIGH, INFERENCE, Confidence
18+
from pylint.interfaces import HIGH, INFERENCE
2019
from pylint.reporters.ureports import nodes as reporter_nodes
21-
from pylint.utils import LinterStats
2220

2321
if TYPE_CHECKING:
22+
from collections.abc import Iterator
23+
24+
from pylint.interfaces import Confidence
2425
from pylint.lint.pylinter import PyLinter
26+
from pylint.utils import LinterStats
2527

2628

2729
class _BasicChecker(BaseChecker):

pylint/checkers/base/basic_error_checker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@
77
from __future__ import annotations
88

99
import itertools
10+
from typing import TYPE_CHECKING
1011

1112
import astroid
1213
from astroid import nodes
13-
from astroid.typing import InferenceResult
1414

1515
from pylint.checkers import utils
1616
from pylint.checkers.base.basic_checker import _BasicChecker
1717
from pylint.checkers.utils import infer_all
1818
from pylint.interfaces import HIGH
1919

20+
if TYPE_CHECKING:
21+
from astroid.typing import InferenceResult
22+
23+
2024
ABC_METACLASSES = {"_py_abc.ABCMeta", "abc.ABCMeta"} # Python 3.7+,
2125
# List of methods which can be redefined
2226
REDEFINABLE_METHODS = frozenset(("__module__",))

pylint/checkers/base/docstring_checker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from __future__ import annotations
88

99
import re
10-
from typing import Literal
10+
from typing import TYPE_CHECKING
11+
1112

1213
import astroid
1314
from astroid import nodes
@@ -21,6 +22,10 @@
2122
is_property_setter,
2223
)
2324

25+
if TYPE_CHECKING:
26+
from typing import Literal
27+
28+
2429
# do not require a doc string on private/system methods
2530
NO_REQUIRED_DOC_RGX = re.compile("^_")
2631

pylint/checkers/base/name_checker/checker.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66

77
from __future__ import annotations
88

9-
import argparse
109
import collections
1110
import itertools
1211
import re
1312
import sys
14-
from collections.abc import Iterable
1513
from enum import Enum, auto
16-
from re import Pattern
1714
from typing import TYPE_CHECKING
1815

1916
import astroid
@@ -29,10 +26,14 @@
2926
_create_naming_options,
3027
)
3128
from pylint.checkers.utils import is_property_deleter, is_property_setter
32-
from pylint.typing import Options
3329

3430
if TYPE_CHECKING:
31+
import argparse
32+
from collections.abc import Iterable
33+
from re import Pattern
34+
3535
from pylint.lint.pylinter import PyLinter
36+
from pylint.typing import Options
3637

3738
_BadNamesTuple = tuple[nodes.NodeNG, str, str, interfaces.Confidence]
3839

pylint/checkers/base/name_checker/naming_style.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
from __future__ import annotations
66

77
import re
8-
from re import Pattern
8+
from typing import TYPE_CHECKING
99

1010
from pylint import constants
11-
from pylint.typing import OptionDict, Options
11+
12+
if TYPE_CHECKING:
13+
from re import Pattern
14+
15+
from pylint.typing import OptionDict, Options
1216

1317

1418
class NamingStyle:

pylint/checkers/base_checker.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,31 @@
66

77
import abc
88
import functools
9-
from collections.abc import Iterable, Sequence
109
from inspect import cleandoc
11-
from tokenize import TokenInfo
12-
from typing import TYPE_CHECKING, Any
13-
14-
from astroid import nodes
10+
from typing import TYPE_CHECKING
1511

1612
from pylint.config.arguments_provider import _ArgumentsProvider
1713
from pylint.constants import _MSG_ORDER, MAIN_CHECKER_NAME, WarningScope
1814
from pylint.exceptions import InvalidMessageError
19-
from pylint.interfaces import Confidence
2015
from pylint.message.message_definition import MessageDefinition
21-
from pylint.typing import (
22-
ExtraMessageOptions,
23-
MessageDefinitionTuple,
24-
OptionDict,
25-
Options,
26-
ReportsCallable,
27-
)
16+
from pylint.typing import ExtraMessageOptions
2817
from pylint.utils import get_rst_section, get_rst_title
2918

3019
if TYPE_CHECKING:
20+
from collections.abc import Iterable, Sequence
21+
from tokenize import TokenInfo
22+
from typing import Any
23+
24+
from astroid import nodes
25+
3126
from pylint.lint import PyLinter
27+
from pylint.interfaces import Confidence
28+
from pylint.typing import (
29+
MessageDefinitionTuple,
30+
OptionDict,
31+
Options,
32+
ReportsCallable,
33+
)
3234

3335

3436
@functools.total_ordering

pylint/checkers/classes/class_checker.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77
from __future__ import annotations
88

99
from collections import defaultdict
10-
from collections.abc import Callable, Sequence
1110
from functools import cached_property
1211
from itertools import chain, zip_longest
13-
from re import Pattern
14-
from typing import TYPE_CHECKING, Any, NamedTuple, Union
12+
from typing import TYPE_CHECKING, NamedTuple
1513

1614
import astroid
17-
from astroid import bases, nodes, util
18-
from astroid.nodes import LocalsDictNodeNG
19-
from astroid.typing import SuccessfulInferenceResult
15+
from astroid import nodes, util
2016

2117
from pylint.checkers import BaseChecker, utils
2218
from pylint.checkers.utils import (
@@ -40,13 +36,21 @@
4036
uninferable_final_decorators,
4137
)
4238
from pylint.interfaces import HIGH, INFERENCE
43-
from pylint.typing import MessageDefinitionTuple
4439

4540
if TYPE_CHECKING:
41+
from collections.abc import Callable, Sequence
42+
from re import Pattern
43+
from typing import Any, Union
44+
45+
from astroid import bases
46+
from astroid.nodes import LocalsDictNodeNG
47+
from astroid.typing import SuccessfulInferenceResult
48+
4649
from pylint.lint.pylinter import PyLinter
50+
from pylint.typing import MessageDefinitionTuple
4751

52+
_AccessNodes = Union[nodes.Attribute, nodes.AssignAttr]
4853

49-
_AccessNodes = Union[nodes.Attribute, nodes.AssignAttr]
5054

5155
INVALID_BASE_CLASSES = {"bool", "range", "slice", "memoryview"}
5256
ALLOWED_PROPERTIES = {"bultins.property", "functools.cached_property"}

pylint/checkers/classes/special_methods_checker.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66

77
from __future__ import annotations
88

9-
from collections.abc import Callable
9+
from typing import TYPE_CHECKING
1010

1111
import astroid
1212
from astroid import bases, nodes, util
13-
from astroid.context import InferenceContext
14-
from astroid.typing import InferenceResult
1513

1614
from pylint.checkers import BaseChecker
1715
from pylint.checkers.utils import (
@@ -22,7 +20,15 @@
2220
only_required_for_messages,
2321
safe_infer,
2422
)
25-
from pylint.lint.pylinter import PyLinter
23+
24+
if TYPE_CHECKING:
25+
from collections.abc import Callable
26+
27+
from astroid.context import InferenceContext
28+
from astroid.typing import InferenceResult
29+
30+
from pylint.lint.pylinter import PyLinter
31+
2632

2733
NEXT_METHOD = "__next__"
2834

pylint/checkers/deprecated.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from __future__ import annotations
88

9-
from collections.abc import Container, Iterable
109
from itertools import chain
10+
from typing import TYPE_CHECKING
1111

1212
import astroid
1313
from astroid import nodes
@@ -17,7 +17,12 @@
1717
from pylint.checkers.base_checker import BaseChecker
1818
from pylint.checkers.utils import get_import_name, infer_all, safe_infer
1919
from pylint.interfaces import INFERENCE
20-
from pylint.typing import MessageDefinitionTuple
20+
21+
if TYPE_CHECKING:
22+
from collections.abc import Container, Iterable
23+
24+
from pylint.typing import MessageDefinitionTuple
25+
2126

2227
ACCEPTABLE_NODES = (
2328
astroid.BoundMethod,

0 commit comments

Comments
 (0)