Skip to content

Commit

Permalink
Add more from __future__ import annotations; remove more quotes (py…
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Aug 15, 2022
1 parent f8fc26e commit 1d9ca64
Show file tree
Hide file tree
Showing 132 changed files with 797 additions and 540 deletions.
2 changes: 2 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os.path

pytest_plugins = ["mypy.test.data"]
Expand Down
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

from __future__ import annotations

import os
import sys

Expand Down
3 changes: 3 additions & 0 deletions misc/actions_stubs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

import os
import shutil
from typing import Any, Tuple
Expand Down
2 changes: 2 additions & 0 deletions misc/analyze_cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python

from __future__ import annotations

import json
import os
import os.path
Expand Down
2 changes: 2 additions & 0 deletions misc/apply-cache-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
many cases instead of full cache artifacts.
"""

from __future__ import annotations

import argparse
import json
import os
Expand Down
4 changes: 3 additions & 1 deletion misc/async_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
testFullCoroutineMatrix in test-data/unit/check-async-await.test.
"""

from __future__ import annotations

import sys
from types import coroutine
from typing import Any, Awaitable, Generator, Iterator
Expand Down Expand Up @@ -35,7 +37,7 @@ async def decorated_coroutine() -> int:
class It(Iterator[str]):
stop = False

def __iter__(self) -> "It":
def __iter__(self) -> It:
return self

def __next__(self) -> str:
Expand Down
2 changes: 2 additions & 0 deletions misc/cherry-pick-typeshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
python3 misc/cherry-pick-typeshed.py --typeshed-dir dir hash
"""

from __future__ import annotations

import argparse
import os.path
import re
Expand Down
2 changes: 2 additions & 0 deletions misc/convert-cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
See mypy/metastore.py for details.
"""

from __future__ import annotations

import os
import sys

Expand Down
2 changes: 2 additions & 0 deletions misc/diff-cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
many cases instead of full cache artifacts.
"""

from __future__ import annotations

import argparse
import json
import os
Expand Down
2 changes: 2 additions & 0 deletions misc/dump-ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Parse source files and print the abstract syntax trees.
"""

from __future__ import annotations

import argparse
import sys
from typing import Tuple
Expand Down
1 change: 1 addition & 0 deletions misc/fix_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def foo(self, bar, baz=12):
Finally, it knows that __init__() is supposed to return None.
"""

from __future__ import annotations

import os
import re
Expand Down
2 changes: 2 additions & 0 deletions misc/incremental_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
python3 misc/incremental_checker.py commit 2a432b
"""

from __future__ import annotations

import base64
import json
import os
Expand Down
2 changes: 2 additions & 0 deletions misc/perf_checker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

import os
import shutil
import statistics
Expand Down
2 changes: 2 additions & 0 deletions misc/proper_plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Callable, Optional, Type as typing_Type

from mypy.nodes import TypeInfo
Expand Down
2 changes: 2 additions & 0 deletions misc/sync-typeshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
By default, sync to the latest typeshed commit.
"""

from __future__ import annotations

import argparse
import os
import shutil
Expand Down
2 changes: 2 additions & 0 deletions misc/test_case_to_actual.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import os.path
import sys
Expand Down
2 changes: 2 additions & 0 deletions misc/touch_checker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

import glob
import os
import shutil
Expand Down
2 changes: 2 additions & 0 deletions misc/upload-pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""

from __future__ import annotations

import argparse
import contextlib
import json
Expand Down
2 changes: 2 additions & 0 deletions misc/variadics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
See https://github.com/python/typing/issues/193#issuecomment-236383893
"""

from __future__ import annotations

LIMIT = 5
BOUND = "object"

Expand Down
3 changes: 3 additions & 0 deletions mypy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Mypy type checker command line tool."""

from __future__ import annotations

import os
import sys
import traceback
Expand Down
2 changes: 2 additions & 0 deletions mypy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"""

from __future__ import annotations

import sys
from io import StringIO
from typing import Callable, List, TextIO, Tuple
Expand Down
2 changes: 2 additions & 0 deletions mypy/applytype.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Callable, Dict, Optional, Sequence

import mypy.subtypes
Expand Down
4 changes: 3 additions & 1 deletion mypy/argmap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Utilities for mapping between actual and formal arguments (and their types)."""

from __future__ import annotations

from typing import TYPE_CHECKING, Callable, List, Optional, Sequence, Set

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

def __init__(self, context: "ArgumentInferContext") -> None:
def __init__(self, context: ArgumentInferContext) -> None:
# Next tuple *args index to use.
self.tuple_index = 0
# Keyword arguments in TypedDict **kwargs used.
Expand Down
4 changes: 3 additions & 1 deletion mypy/binder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from collections import defaultdict
from contextlib import contextmanager
from typing import DefaultDict, Dict, Iterator, List, Optional, Set, Tuple, Union, cast
Expand Down Expand Up @@ -234,7 +236,7 @@ def pop_frame(self, can_skip: bool, fall_through: int) -> Frame:
return result

@contextmanager
def accumulate_type_assignments(self) -> "Iterator[Assigns]":
def accumulate_type_assignments(self) -> Iterator[Assigns]:
"""Push a new map to collect assigned types in multiassign from union.
If this map is not None, actual binding is deferred until all items in
Expand Down
2 changes: 2 additions & 0 deletions mypy/bogus_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
For those cases some other technique should be used.
"""

from __future__ import annotations

from typing import Any, TypeVar

from mypy_extensions import FlexibleAlias
Expand Down
18 changes: 10 additions & 8 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"""
# TODO: More consistent terminology, e.g. path/fnam, module/id, state/file

from __future__ import annotations

import contextlib
import errno
import gc
Expand Down Expand Up @@ -132,7 +134,7 @@ class BuildResult:
errors: List of error messages.
"""

def __init__(self, manager: "BuildManager", graph: Graph) -> None:
def __init__(self, manager: BuildManager, graph: Graph) -> None:
self.manager = manager
self.graph = graph
self.files = manager.modules
Expand Down Expand Up @@ -600,7 +602,7 @@ def __init__(
search_paths: SearchPaths,
ignore_prefix: str,
source_set: BuildSourceSet,
reports: "Optional[Reports]",
reports: Optional[Reports],
options: Options,
version_id: str,
plugin: Plugin,
Expand Down Expand Up @@ -1857,7 +1859,7 @@ class State:
import_context: List[Tuple[str, int]]

# The State from which this module was imported, if any
caller_state: Optional["State"] = None
caller_state: Optional[State] = None

# If caller_state is set, the line number in the caller where the import occurred
caller_line = 0
Expand Down Expand Up @@ -1896,9 +1898,9 @@ def __init__(
path: Optional[str],
source: Optional[str],
manager: BuildManager,
caller_state: "Optional[State]" = None,
caller_state: Optional[State] = None,
caller_line: int = 0,
ancestor_for: "Optional[State]" = None,
ancestor_for: Optional[State] = None,
root_source: bool = False,
# If `temporary` is True, this State is being created to just
# quickly parse/load the tree, without an intention to further
Expand Down Expand Up @@ -2545,9 +2547,9 @@ def find_module_and_diagnose(
manager: BuildManager,
id: str,
options: Options,
caller_state: "Optional[State]" = None,
caller_state: Optional[State] = None,
caller_line: int = 0,
ancestor_for: "Optional[State]" = None,
ancestor_for: Optional[State] = None,
root_source: bool = False,
skip_diagnose: bool = False,
) -> Tuple[str, str]:
Expand Down Expand Up @@ -2765,7 +2767,7 @@ def skipping_module(
manager.errors.set_import_context(save_import_context)


def skipping_ancestor(manager: BuildManager, id: str, path: str, ancestor_for: "State") -> None:
def skipping_ancestor(manager: BuildManager, id: str, path: str, ancestor_for: State) -> None:
"""Produce an error for an ancestor ignored due to --follow_imports=error"""
# TODO: Read the path (the __init__.py file) and return
# immediately if it's empty or only contains comments.
Expand Down
6 changes: 4 additions & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Mypy type checker."""

from __future__ import annotations

import fnmatch
import itertools
from collections import defaultdict
Expand Down Expand Up @@ -301,7 +303,7 @@ class TypeChecker(NodeVisitor[None], CheckerPluginInterface):
pattern_checker: PatternChecker

tscope: Scope
scope: "CheckerScope"
scope: CheckerScope
# Stack of function return types
return_types: List[Type]
# Flags; true for dynamically typed functions
Expand Down Expand Up @@ -5966,7 +5968,7 @@ def iterable_item_type(self, instance: Instance) -> Type:
def function_type(self, func: FuncBase) -> FunctionLike:
return function_type(func, self.named_type("builtins.function"))

def push_type_map(self, type_map: "TypeMap") -> None:
def push_type_map(self, type_map: TypeMap) -> None:
if type_map is None:
self.binder.unreachable()
else:
Expand Down
10 changes: 5 additions & 5 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Expression type checker. This file is conceptually part of TypeChecker."""

from __future__ import annotations

import itertools
from contextlib import contextmanager
from typing import (
Expand Down Expand Up @@ -253,7 +255,7 @@ class ExpressionChecker(ExpressionVisitor[Type]):
"""

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

def __init__(
self, chk: "mypy.checker.TypeChecker", msg: MessageBuilder, plugin: Plugin
) -> None:
def __init__(self, chk: mypy.checker.TypeChecker, msg: MessageBuilder, plugin: Plugin) -> None:
"""Construct an expression type checker."""
self.chk = chk
self.msg = msg
Expand Down Expand Up @@ -654,7 +654,7 @@ def check_typeddict_call(
self.chk.fail(message_registry.INVALID_TYPEDDICT_ARGS, context)
return AnyType(TypeOfAny.from_error)

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

item_names = [] # List[str]
Expand Down
8 changes: 5 additions & 3 deletions mypy/checkmember.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Type checking of attribute access"""

from __future__ import annotations

from typing import TYPE_CHECKING, Callable, Optional, Sequence, Union, cast

from mypy import meet, message_registry, subtypes
Expand Down Expand Up @@ -85,7 +87,7 @@ def __init__(
original_type: Type,
context: Context,
msg: MessageBuilder,
chk: "mypy.checker.TypeChecker",
chk: mypy.checker.TypeChecker,
self_type: Optional[Type],
module_symbol_table: Optional[SymbolTable] = None,
) -> None:
Expand All @@ -111,7 +113,7 @@ def copy_modified(
messages: Optional[MessageBuilder] = None,
self_type: Optional[Type] = None,
is_lvalue: Optional[bool] = None,
) -> "MemberContext":
) -> MemberContext:
mx = MemberContext(
self.is_lvalue,
self.is_super,
Expand Down Expand Up @@ -142,7 +144,7 @@ def analyze_member_access(
msg: MessageBuilder,
*,
original_type: Type,
chk: "mypy.checker.TypeChecker",
chk: mypy.checker.TypeChecker,
override_info: Optional[TypeInfo] = None,
in_literal_context: bool = False,
self_type: Optional[Type] = None,
Expand Down
Loading

0 comments on commit 1d9ca64

Please sign in to comment.