Skip to content

Commit 5ead29c

Browse files
committed
Fix typing.Counter import for Python 3.6.0
typing.Counter was added in Python 3.6.1. In the strings checker, guard the import with TYPE_CHECKING and use a type annotation comment to fix usage with Python 3.6.0.
1 parent 21420c0 commit 5ead29c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pylint/checkers/strings.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@
3838
import numbers
3939
import re
4040
import tokenize
41-
from typing import Counter, Iterable
41+
from typing import TYPE_CHECKING, Iterable
4242

4343
import astroid
4444

4545
from pylint.checkers import BaseChecker, BaseTokenChecker, utils
4646
from pylint.checkers.utils import check_messages
4747
from pylint.interfaces import IAstroidChecker, IRawChecker, ITokenChecker
4848

49+
if TYPE_CHECKING:
50+
from typing import Counter # typing.Counter added in Python 3.6.1
51+
4952
_AST_NODE_STR_TYPES = ("__builtin__.unicode", "__builtin__.str", "builtins.str")
5053
# Prefixes for both strings and bytes literals per
5154
# https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
@@ -750,7 +753,8 @@ def check_for_consistent_string_delimiters(
750753
Args:
751754
tokens: The tokens to be checked against for consistent usage.
752755
"""
753-
string_delimiters: Counter[str] = collections.Counter()
756+
# typing.Counter added in Python 3.6.1 so this type hint must be a comment
757+
string_delimiters = collections.Counter() # type: Counter[str]
754758

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

0 commit comments

Comments
 (0)