Skip to content

Commit 1d9ca64

Browse files
authored
Add more from __future__ import annotations; remove more quotes (#13412)
1 parent f8fc26e commit 1d9ca64

File tree

132 files changed

+797
-540
lines changed

Some content is hidden

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

132 files changed

+797
-540
lines changed

conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os.path
24

35
pytest_plugins = ["mypy.test.data"]

docs/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
1414

15+
from __future__ import annotations
16+
1517
import os
1618
import sys
1719

misc/actions_stubs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env python3
2+
3+
from __future__ import annotations
4+
25
import os
36
import shutil
47
from typing import Any, Tuple

misc/analyze_cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
from __future__ import annotations
4+
35
import json
46
import os
57
import os.path

misc/apply-cache-diff.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
many cases instead of full cache artifacts.
66
"""
77

8+
from __future__ import annotations
9+
810
import argparse
911
import json
1012
import os

misc/async_matrix.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
testFullCoroutineMatrix in test-data/unit/check-async-await.test.
66
"""
77

8+
from __future__ import annotations
9+
810
import sys
911
from types import coroutine
1012
from typing import Any, Awaitable, Generator, Iterator
@@ -35,7 +37,7 @@ async def decorated_coroutine() -> int:
3537
class It(Iterator[str]):
3638
stop = False
3739

38-
def __iter__(self) -> "It":
40+
def __iter__(self) -> It:
3941
return self
4042

4143
def __next__(self) -> str:

misc/cherry-pick-typeshed.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
python3 misc/cherry-pick-typeshed.py --typeshed-dir dir hash
66
"""
77

8+
from __future__ import annotations
9+
810
import argparse
911
import os.path
1012
import re

misc/convert-cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
See mypy/metastore.py for details.
66
"""
77

8+
from __future__ import annotations
9+
810
import os
911
import sys
1012

misc/diff-cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
many cases instead of full cache artifacts.
66
"""
77

8+
from __future__ import annotations
9+
810
import argparse
911
import json
1012
import os

misc/dump-ast.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Parse source files and print the abstract syntax trees.
44
"""
55

6+
from __future__ import annotations
7+
68
import argparse
79
import sys
810
from typing import Tuple

misc/fix_annotate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def foo(self, bar, baz=12):
2727
Finally, it knows that __init__() is supposed to return None.
2828
"""
2929

30+
from __future__ import annotations
3031

3132
import os
3233
import re

misc/incremental_checker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
python3 misc/incremental_checker.py commit 2a432b
3232
"""
3333

34+
from __future__ import annotations
35+
3436
import base64
3537
import json
3638
import os

misc/perf_checker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22

3+
from __future__ import annotations
4+
35
import os
46
import shutil
57
import statistics

misc/proper_plugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Callable, Optional, Type as typing_Type
24

35
from mypy.nodes import TypeInfo

misc/sync-typeshed.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
By default, sync to the latest typeshed commit.
88
"""
99

10+
from __future__ import annotations
11+
1012
import argparse
1113
import os
1214
import shutil

misc/test_case_to_actual.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24
import os.path
35
import sys

misc/touch_checker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22

3+
from __future__ import annotations
4+
35
import glob
46
import os
57
import shutil

misc/upload-pypi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
66
"""
77

8+
from __future__ import annotations
9+
810
import argparse
911
import contextlib
1012
import json

misc/variadics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
See https://github.com/python/typing/issues/193#issuecomment-236383893
44
"""
55

6+
from __future__ import annotations
7+
68
LIMIT = 5
79
BOUND = "object"
810

mypy/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
"""Mypy type checker command line tool."""
2+
3+
from __future__ import annotations
4+
25
import os
36
import sys
47
import traceback

mypy/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
4444
"""
4545

46+
from __future__ import annotations
47+
4648
import sys
4749
from io import StringIO
4850
from typing import Callable, List, TextIO, Tuple

mypy/applytype.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Callable, Dict, Optional, Sequence
24

35
import mypy.subtypes

mypy/argmap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Utilities for mapping between actual and formal arguments (and their types)."""
22

3+
from __future__ import annotations
4+
35
from typing import TYPE_CHECKING, Callable, List, Optional, Sequence, Set
46

57
from mypy import nodes
@@ -158,7 +160,7 @@ def f(x: int, *args: str) -> None: ...
158160
needs a separate instance since instances have per-call state.
159161
"""
160162

161-
def __init__(self, context: "ArgumentInferContext") -> None:
163+
def __init__(self, context: ArgumentInferContext) -> None:
162164
# Next tuple *args index to use.
163165
self.tuple_index = 0
164166
# Keyword arguments in TypedDict **kwargs used.

mypy/binder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from collections import defaultdict
24
from contextlib import contextmanager
35
from typing import DefaultDict, Dict, Iterator, List, Optional, Set, Tuple, Union, cast
@@ -234,7 +236,7 @@ def pop_frame(self, can_skip: bool, fall_through: int) -> Frame:
234236
return result
235237

236238
@contextmanager
237-
def accumulate_type_assignments(self) -> "Iterator[Assigns]":
239+
def accumulate_type_assignments(self) -> Iterator[Assigns]:
238240
"""Push a new map to collect assigned types in multiassign from union.
239241
240242
If this map is not None, actual binding is deferred until all items in

mypy/bogus_type.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
For those cases some other technique should be used.
1111
"""
1212

13+
from __future__ import annotations
14+
1315
from typing import Any, TypeVar
1416

1517
from mypy_extensions import FlexibleAlias

mypy/build.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"""
1111
# TODO: More consistent terminology, e.g. path/fnam, module/id, state/file
1212

13+
from __future__ import annotations
14+
1315
import contextlib
1416
import errno
1517
import gc
@@ -132,7 +134,7 @@ class BuildResult:
132134
errors: List of error messages.
133135
"""
134136

135-
def __init__(self, manager: "BuildManager", graph: Graph) -> None:
137+
def __init__(self, manager: BuildManager, graph: Graph) -> None:
136138
self.manager = manager
137139
self.graph = graph
138140
self.files = manager.modules
@@ -600,7 +602,7 @@ def __init__(
600602
search_paths: SearchPaths,
601603
ignore_prefix: str,
602604
source_set: BuildSourceSet,
603-
reports: "Optional[Reports]",
605+
reports: Optional[Reports],
604606
options: Options,
605607
version_id: str,
606608
plugin: Plugin,
@@ -1857,7 +1859,7 @@ class State:
18571859
import_context: List[Tuple[str, int]]
18581860

18591861
# The State from which this module was imported, if any
1860-
caller_state: Optional["State"] = None
1862+
caller_state: Optional[State] = None
18611863

18621864
# If caller_state is set, the line number in the caller where the import occurred
18631865
caller_line = 0
@@ -1896,9 +1898,9 @@ def __init__(
18961898
path: Optional[str],
18971899
source: Optional[str],
18981900
manager: BuildManager,
1899-
caller_state: "Optional[State]" = None,
1901+
caller_state: Optional[State] = None,
19001902
caller_line: int = 0,
1901-
ancestor_for: "Optional[State]" = None,
1903+
ancestor_for: Optional[State] = None,
19021904
root_source: bool = False,
19031905
# If `temporary` is True, this State is being created to just
19041906
# quickly parse/load the tree, without an intention to further
@@ -2545,9 +2547,9 @@ def find_module_and_diagnose(
25452547
manager: BuildManager,
25462548
id: str,
25472549
options: Options,
2548-
caller_state: "Optional[State]" = None,
2550+
caller_state: Optional[State] = None,
25492551
caller_line: int = 0,
2550-
ancestor_for: "Optional[State]" = None,
2552+
ancestor_for: Optional[State] = None,
25512553
root_source: bool = False,
25522554
skip_diagnose: bool = False,
25532555
) -> Tuple[str, str]:
@@ -2765,7 +2767,7 @@ def skipping_module(
27652767
manager.errors.set_import_context(save_import_context)
27662768

27672769

2768-
def skipping_ancestor(manager: BuildManager, id: str, path: str, ancestor_for: "State") -> None:
2770+
def skipping_ancestor(manager: BuildManager, id: str, path: str, ancestor_for: State) -> None:
27692771
"""Produce an error for an ancestor ignored due to --follow_imports=error"""
27702772
# TODO: Read the path (the __init__.py file) and return
27712773
# immediately if it's empty or only contains comments.

mypy/checker.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Mypy type checker."""
22

3+
from __future__ import annotations
4+
35
import fnmatch
46
import itertools
57
from collections import defaultdict
@@ -301,7 +303,7 @@ class TypeChecker(NodeVisitor[None], CheckerPluginInterface):
301303
pattern_checker: PatternChecker
302304

303305
tscope: Scope
304-
scope: "CheckerScope"
306+
scope: CheckerScope
305307
# Stack of function return types
306308
return_types: List[Type]
307309
# Flags; true for dynamically typed functions
@@ -5966,7 +5968,7 @@ def iterable_item_type(self, instance: Instance) -> Type:
59665968
def function_type(self, func: FuncBase) -> FunctionLike:
59675969
return function_type(func, self.named_type("builtins.function"))
59685970

5969-
def push_type_map(self, type_map: "TypeMap") -> None:
5971+
def push_type_map(self, type_map: TypeMap) -> None:
59705972
if type_map is None:
59715973
self.binder.unreachable()
59725974
else:

mypy/checkexpr.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Expression type checker. This file is conceptually part of TypeChecker."""
22

3+
from __future__ import annotations
4+
35
import itertools
46
from contextlib import contextmanager
57
from typing import (
@@ -253,7 +255,7 @@ class ExpressionChecker(ExpressionVisitor[Type]):
253255
"""
254256

255257
# Some services are provided by a TypeChecker instance.
256-
chk: "mypy.checker.TypeChecker"
258+
chk: mypy.checker.TypeChecker
257259
# This is shared with TypeChecker, but stored also here for convenience.
258260
msg: MessageBuilder
259261
# Type context for type inference
@@ -265,9 +267,7 @@ class ExpressionChecker(ExpressionVisitor[Type]):
265267
strfrm_checker: StringFormatterChecker
266268
plugin: Plugin
267269

268-
def __init__(
269-
self, chk: "mypy.checker.TypeChecker", msg: MessageBuilder, plugin: Plugin
270-
) -> None:
270+
def __init__(self, chk: mypy.checker.TypeChecker, msg: MessageBuilder, plugin: Plugin) -> None:
271271
"""Construct an expression type checker."""
272272
self.chk = chk
273273
self.msg = msg
@@ -654,7 +654,7 @@ def check_typeddict_call(
654654
self.chk.fail(message_registry.INVALID_TYPEDDICT_ARGS, context)
655655
return AnyType(TypeOfAny.from_error)
656656

657-
def validate_typeddict_kwargs(self, kwargs: DictExpr) -> "Optional[Dict[str, Expression]]":
657+
def validate_typeddict_kwargs(self, kwargs: DictExpr) -> Optional[Dict[str, Expression]]:
658658
item_args = [item[1] for item in kwargs.items]
659659

660660
item_names = [] # List[str]

mypy/checkmember.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Type checking of attribute access"""
22

3+
from __future__ import annotations
4+
35
from typing import TYPE_CHECKING, Callable, Optional, Sequence, Union, cast
46

57
from mypy import meet, message_registry, subtypes
@@ -85,7 +87,7 @@ def __init__(
8587
original_type: Type,
8688
context: Context,
8789
msg: MessageBuilder,
88-
chk: "mypy.checker.TypeChecker",
90+
chk: mypy.checker.TypeChecker,
8991
self_type: Optional[Type],
9092
module_symbol_table: Optional[SymbolTable] = None,
9193
) -> None:
@@ -111,7 +113,7 @@ def copy_modified(
111113
messages: Optional[MessageBuilder] = None,
112114
self_type: Optional[Type] = None,
113115
is_lvalue: Optional[bool] = None,
114-
) -> "MemberContext":
116+
) -> MemberContext:
115117
mx = MemberContext(
116118
self.is_lvalue,
117119
self.is_super,
@@ -142,7 +144,7 @@ def analyze_member_access(
142144
msg: MessageBuilder,
143145
*,
144146
original_type: Type,
145-
chk: "mypy.checker.TypeChecker",
147+
chk: mypy.checker.TypeChecker,
146148
override_info: Optional[TypeInfo] = None,
147149
in_literal_context: bool = False,
148150
self_type: Optional[Type] = None,

0 commit comments

Comments
 (0)