Skip to content

Commit 6fb5624

Browse files
committed
Import typing names directly
1 parent a122631 commit 6fb5624

File tree

4 files changed

+18
-36
lines changed

4 files changed

+18
-36
lines changed

pylint/checkers/strings.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import numbers
4040
import re
4141
import tokenize
42-
from typing import TYPE_CHECKING, Iterable
42+
from typing import Counter, Iterable
4343

4444
import astroid
4545
from astroid import nodes
@@ -48,9 +48,6 @@
4848
from pylint.checkers.utils import check_messages
4949
from pylint.interfaces import IAstroidChecker, IRawChecker, ITokenChecker
5050

51-
if TYPE_CHECKING:
52-
from typing import Counter # typing.Counter added in Python 3.6.1
53-
5451
_AST_NODE_STR_TYPES = ("__builtin__.unicode", "__builtin__.str", "builtins.str")
5552
# Prefixes for both strings and bytes literals per
5653
# https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
@@ -769,8 +766,7 @@ def check_for_consistent_string_delimiters(
769766
Args:
770767
tokens: The tokens to be checked against for consistent usage.
771768
"""
772-
# typing.Counter added in Python 3.6.1 so this type hint must be a comment
773-
string_delimiters = collections.Counter() # type: Counter[str]
769+
string_delimiters: Counter[str] = collections.Counter()
774770

775771
# First, figure out which quote character predominates in the module
776772
for tok_type, token, _, _, _ in tokens:

pylint/message/message_id_store.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
3-
import sys
4-
from typing import Dict, List, Optional, Tuple
3+
from typing import Dict, List, NoReturn, Optional, Tuple
54

65
from pylint.exceptions import InvalidMessageError, UnknownMessageError
76

8-
if sys.version_info >= (3, 6, 2):
9-
from typing import NoReturn
10-
else:
11-
from typing_extensions import NoReturn
12-
137

148
class MessageIdStore:
159

pylint/testutils/lint_module_test.py

+14-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import sys
88
from collections import Counter
99
from io import StringIO
10-
from typing import TYPE_CHECKING, Dict, List, Optional, TextIO, Tuple
10+
from typing import Counter as CounterType
11+
from typing import Dict, List, Optional, TextIO, Tuple
1112

1213
import pytest
1314
from _pytest.config import Config
@@ -25,10 +26,7 @@
2526
from pylint.testutils.reporter_for_tests import FunctionalTestReporter
2627
from pylint.utils import utils
2728

28-
if TYPE_CHECKING:
29-
from typing import Counter as CounterType # typing.Counter added in Python 3.6.1
30-
31-
MessageCounter = CounterType[Tuple[int, str]]
29+
MessageCounter = CounterType[Tuple[int, str]]
3230

3331

3432
class LintModuleTest:
@@ -96,15 +94,15 @@ def __str__(self) -> str:
9694
return f"{self._test_file.base} ({self.__class__.__module__}.{self.__class__.__name__})"
9795

9896
@staticmethod
99-
def get_expected_messages(stream: TextIO) -> "MessageCounter":
97+
def get_expected_messages(stream: TextIO) -> MessageCounter:
10098
"""Parses a file and get expected messages.
10199
102100
:param stream: File-like input stream.
103101
:type stream: enumerable
104102
:returns: A dict mapping line,msg-symbol tuples to the count on this line.
105103
:rtype: dict
106104
"""
107-
messages: "MessageCounter" = Counter()
105+
messages: MessageCounter = Counter()
108106
for i, line in enumerate(stream):
109107
match = _EXPECTED_RE.search(line)
110108
if match is None:
@@ -130,9 +128,9 @@ def get_expected_messages(stream: TextIO) -> "MessageCounter":
130128

131129
@staticmethod
132130
def multiset_difference(
133-
expected_entries: "MessageCounter",
134-
actual_entries: "MessageCounter",
135-
) -> Tuple["MessageCounter", Dict[Tuple[int, str], int]]:
131+
expected_entries: MessageCounter,
132+
actual_entries: MessageCounter,
133+
) -> Tuple[MessageCounter, Dict[Tuple[int, str], int]]:
136134
"""Takes two multisets and compares them.
137135
138136
A multiset is a dict with the cardinality of the key as the value."""
@@ -161,7 +159,7 @@ def _open_source_file(self) -> TextIO:
161159
return open(self._test_file.source, encoding="latin1")
162160
return open(self._test_file.source, encoding="utf8")
163161

164-
def _get_expected(self) -> Tuple["MessageCounter", List[OutputLine]]:
162+
def _get_expected(self) -> Tuple[MessageCounter, List[OutputLine]]:
165163
with self._open_source_file() as f:
166164
expected_msgs = self.get_expected_messages(f)
167165
if not expected_msgs:
@@ -172,10 +170,10 @@ def _get_expected(self) -> Tuple["MessageCounter", List[OutputLine]]:
172170
]
173171
return expected_msgs, expected_output_lines
174172

175-
def _get_actual(self) -> Tuple["MessageCounter", List[OutputLine]]:
173+
def _get_actual(self) -> Tuple[MessageCounter, List[OutputLine]]:
176174
messages: List[Message] = self._linter.reporter.messages
177175
messages.sort(key=lambda m: (m.line, m.symbol, m.msg))
178-
received_msgs: "MessageCounter" = Counter()
176+
received_msgs: MessageCounter = Counter()
179177
received_output_lines = []
180178
for msg in messages:
181179
assert (
@@ -200,8 +198,8 @@ def _runTest(self) -> None:
200198

201199
def error_msg_for_unequal_messages(
202200
self,
203-
actual_messages: "MessageCounter",
204-
expected_messages: "MessageCounter",
201+
actual_messages: MessageCounter,
202+
expected_messages: MessageCounter,
205203
actual_output: List[OutputLine],
206204
) -> str:
207205
msg = [f'Wrong results for file "{self._test_file.base}":']
@@ -246,7 +244,7 @@ def error_msg_for_unequal_output(
246244

247245
def _check_output_text(
248246
self,
249-
_: "MessageCounter",
247+
_: MessageCounter,
250248
expected_output: List[OutputLine],
251249
actual_output: List[OutputLine],
252250
) -> None:

tests/lint/test_pylinter.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import sys
2-
from typing import Any
1+
from typing import Any, NoReturn
32
from unittest.mock import patch
43

54
from _pytest.capture import CaptureFixture
@@ -9,11 +8,6 @@
98
from pylint.lint.pylinter import PyLinter
109
from pylint.utils import FileState
1110

12-
if sys.version_info >= (3, 6, 2):
13-
from typing import NoReturn
14-
else:
15-
from typing_extensions import NoReturn
16-
1711

1812
def raise_exception(*args: Any, **kwargs: Any) -> NoReturn:
1913
raise AstroidBuildingError(modname="spam")

0 commit comments

Comments
 (0)