Skip to content

Commit 3aebb87

Browse files
authored
Modernize a few Counter/DefaultDict annotations (#13463)
1 parent 4d4326a commit 3aebb87

File tree

7 files changed

+13
-16
lines changed

7 files changed

+13
-16
lines changed

mypy/nodes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
TYPE_CHECKING,
1111
Any,
1212
Callable,
13-
DefaultDict,
1413
Dict,
1514
Iterator,
1615
Optional,
@@ -306,7 +305,7 @@ class MypyFile(SymbolNode):
306305
# Top-level definitions and statements
307306
defs: list[Statement]
308307
# Type alias dependencies as mapping from target to set of alias full names
309-
alias_deps: DefaultDict[str, set[str]]
308+
alias_deps: defaultdict[str, set[str]]
310309
# Is there a UTF-8 BOM at the start?
311310
is_bom: bool
312311
names: SymbolTable

mypy/report.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import sys
1111
import time
1212
import tokenize
13-
import typing
1413
from abc import ABCMeta, abstractmethod
1514
from operator import attrgetter
1615
from typing import Any, Callable, Dict, Iterator, Tuple, cast
@@ -211,7 +210,7 @@ class AnyExpressionsReporter(AbstractReporter):
211210
def __init__(self, reports: Reports, output_dir: str) -> None:
212211
super().__init__(reports, output_dir)
213212
self.counts: dict[str, tuple[int, int]] = {}
214-
self.any_types_counter: dict[str, typing.Counter[int]] = {}
213+
self.any_types_counter: dict[str, collections.Counter[int]] = {}
215214

216215
def on_file(
217216
self,
@@ -286,7 +285,7 @@ def _report_any_exprs(self) -> None:
286285
self._write_out_report("any-exprs.txt", column_names, rows, total_row)
287286

288287
def _report_types_of_anys(self) -> None:
289-
total_counter: typing.Counter[int] = collections.Counter()
288+
total_counter: collections.Counter[int] = collections.Counter()
290289
for counter in self.any_types_counter.values():
291290
for any_type, value in counter.items():
292291
total_counter[any_type] += value
@@ -528,7 +527,7 @@ def on_file(
528527
def _get_any_info_for_line(visitor: stats.StatisticsVisitor, lineno: int) -> str:
529528
if lineno in visitor.any_line_map:
530529
result = "Any Types on this line: "
531-
counter: typing.Counter[int] = collections.Counter()
530+
counter: collections.Counter[int] = collections.Counter()
532531
for typ in visitor.any_line_map[lineno]:
533532
counter[typ.type_of_any] += 1
534533
for any_type, occurrences in counter.items():

mypy/server/deps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class 'mod.Cls'. This can also refer to an attribute inherited from a
8181

8282
from __future__ import annotations
8383

84-
from typing import DefaultDict, List
84+
from collections import defaultdict
85+
from typing import List
8586

8687
from mypy.nodes import (
8788
GDEF,
@@ -220,7 +221,7 @@ def __init__(
220221
self,
221222
type_map: dict[Expression, Type],
222223
python_version: tuple[int, int],
223-
alias_deps: DefaultDict[str, set[str]],
224+
alias_deps: defaultdict[str, set[str]],
224225
options: Options | None = None,
225226
) -> None:
226227
self.scope = Scope()

mypy/stats.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import os
6-
import typing
76
from collections import Counter
87
from contextlib import contextmanager
98
from typing import Iterator, cast
@@ -102,7 +101,7 @@ def __init__(
102101

103102
self.line_map: dict[int, int] = {}
104103

105-
self.type_of_any_counter: typing.Counter[int] = Counter()
104+
self.type_of_any_counter: Counter[int] = Counter()
106105
self.any_line_map: dict[int, list[AnyType]] = {}
107106

108107
# For each scope (top level/function), whether the scope was type checked

mypy/test/testdeps.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import os
66
from collections import defaultdict
7-
from typing import DefaultDict
87

98
from mypy import build
109
from mypy.errors import CompileError
@@ -40,7 +39,7 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
4039
if not a:
4140
a = ["Unknown compile error (likely syntax error in test case or fixture)"]
4241
else:
43-
deps: DefaultDict[str, set[str]] = defaultdict(set)
42+
deps: defaultdict[str, set[str]] = defaultdict(set)
4443
for module in files:
4544
if (
4645
module in dumped_modules

mypyc/irbuild/function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from __future__ import annotations
1414

1515
from collections import defaultdict
16-
from typing import DefaultDict, NamedTuple, Sequence
16+
from typing import NamedTuple, Sequence
1717

1818
from mypy.nodes import (
1919
ArgKind,
@@ -933,7 +933,7 @@ def maybe_insert_into_registry_dict(builder: IRBuilder, fitem: FuncDef) -> None:
933933
line = fitem.line
934934
is_singledispatch_main_func = fitem in builder.singledispatch_impls
935935
# dict of singledispatch_func to list of register_types (fitem is the function to register)
936-
to_register: DefaultDict[FuncDef, list[TypeInfo]] = defaultdict(list)
936+
to_register: defaultdict[FuncDef, list[TypeInfo]] = defaultdict(list)
937937
for main_func, impls in builder.singledispatch_impls.items():
938938
for dispatch_type, impl in impls:
939939
if fitem == impl:

mypyc/irbuild/prepare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from __future__ import annotations
1515

1616
from collections import defaultdict
17-
from typing import DefaultDict, Iterable, NamedTuple, Tuple
17+
from typing import Iterable, NamedTuple, Tuple
1818

1919
from mypy.build import Graph
2020
from mypy.nodes import (
@@ -379,7 +379,7 @@ def __init__(self, errors: Errors) -> None:
379379
super().__init__()
380380

381381
# Map of main singledispatch function to list of registered implementations
382-
self.singledispatch_impls: DefaultDict[FuncDef, list[RegisterImplInfo]] = defaultdict(list)
382+
self.singledispatch_impls: defaultdict[FuncDef, list[RegisterImplInfo]] = defaultdict(list)
383383

384384
# Map of decorated function to the indices of any decorators to remove
385385
self.decorators_to_remove: dict[FuncDef, list[int]] = {}

0 commit comments

Comments
 (0)