Skip to content

Commit

Permalink
Add from __future__ import annotations everywhere. (#13391)
Browse files Browse the repository at this point in the history
This will be nice for if anyone wants to use slicker new syntax for mypy internals without 
worrying about if the file already has it or not.
  • Loading branch information
jhance authored Aug 12, 2022
1 parent 9242046 commit b1364c5
Show file tree
Hide file tree
Showing 141 changed files with 282 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mypy/dmypy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from mypy.dmypy.client import console_entry

if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions mypy/dmypy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
rather than having to read it back from disk on each run.
"""

from __future__ import annotations

import argparse
import base64
import json
Expand Down
2 changes: 2 additions & 0 deletions mypy/plugins/attrs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Plugin for supporting the attrs library (http://www.attrs.org)"""

from __future__ import annotations

from typing import Dict, Iterable, List, Optional, Tuple, cast
from typing_extensions import Final

Expand Down
2 changes: 2 additions & 0 deletions mypy/plugins/common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import List, Optional, Union

from mypy.fixup import TypeFixer
Expand Down
2 changes: 2 additions & 0 deletions mypy/plugins/ctypes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Plugin to provide accurate types for some parts of the ctypes module."""

from __future__ import annotations

from typing import List, Optional

# Fully qualified instead of "from mypy.plugin import ..." to avoid circular import problems.
Expand Down
2 changes: 2 additions & 0 deletions mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Plugin that provides support for dataclasses."""

from __future__ import annotations

from typing import Dict, List, Optional, Set, Tuple
from typing_extensions import Final

Expand Down
2 changes: 2 additions & 0 deletions mypy/plugins/default.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from functools import partial
from typing import Callable, List, Optional

Expand Down
2 changes: 2 additions & 0 deletions mypy/plugins/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
we actually bake some of it directly in to the semantic analysis layer (see
semanal_enum.py).
"""
from __future__ import annotations

from typing import Iterable, Optional, Sequence, TypeVar, cast
from typing_extensions import Final

Expand Down
2 changes: 2 additions & 0 deletions mypy/plugins/functools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Plugin for supporting the functools standard library module."""
from __future__ import annotations

from typing import Dict, NamedTuple, Optional
from typing_extensions import Final

Expand Down
2 changes: 2 additions & 0 deletions mypy/plugins/singledispatch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import List, NamedTuple, Optional, Sequence, TypeVar, Union
from typing_extensions import Final

Expand Down
2 changes: 2 additions & 0 deletions mypy/server/astdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class level -- these are handled at attribute level (say, 'mod.Cls.method'
fine-grained dependencies.
"""

from __future__ import annotations

from typing import Dict, Optional, Sequence, Set, Tuple, Union

from mypy.nodes import (
Expand Down
2 changes: 2 additions & 0 deletions mypy/server/astmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
See the main entry point merge_asts for more details.
"""

from __future__ import annotations

from typing import Dict, List, Optional, Tuple, TypeVar, cast

from mypy.nodes import (
Expand Down
2 changes: 2 additions & 0 deletions mypy/server/aststrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
even though some identities are preserved.
"""

from __future__ import annotations

from contextlib import contextmanager, nullcontext
from typing import Dict, Iterator, Optional, Tuple, Union

Expand Down
2 changes: 2 additions & 0 deletions mypy/server/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class 'mod.Cls'. This can also refer to an attribute inherited from a
Test cases for this module live in 'test-data/unit/deps*.test'.
"""

from __future__ import annotations

from typing import DefaultDict, Dict, List, Optional, Set, Tuple

from mypy.nodes import (
Expand Down
2 changes: 2 additions & 0 deletions mypy/server/mergecheck.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Check for duplicate AST nodes after merge."""

from __future__ import annotations

from typing import Dict, List, Tuple
from typing_extensions import Final

Expand Down
2 changes: 2 additions & 0 deletions mypy/server/objgraph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Find all objects reachable from a root object."""

from __future__ import annotations

import types
import weakref
from collections.abc import Iterable
Expand Down
2 changes: 2 additions & 0 deletions mypy/server/subexpr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Find all subexpressions of an AST node."""

from __future__ import annotations

from typing import List

from mypy.nodes import (
Expand Down
2 changes: 2 additions & 0 deletions mypy/server/trigger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""AST triggers that are used for fine-grained dependency handling."""

from __future__ import annotations

from typing_extensions import Final

# Used as a suffix for triggers to handle "from m import *" dependencies (see also
Expand Down
2 changes: 2 additions & 0 deletions mypy/server/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
test cases (test-data/unit/fine-grained*.test).
"""

from __future__ import annotations

import os
import sys
import time
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os.path

provided_prefix = os.getenv("MYPY_TEST_PREFIX", None)
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Utilities for processing .test files containing test case descriptions."""

from __future__ import annotations

import os
import os.path
import posixpath
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import contextlib
import os
import pathlib
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/test_find_sources.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

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

import sys
from io import StringIO

Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
defaults, and that argparse doesn't assign any new members to the Options
object it creates.
"""
from __future__ import annotations

import argparse
import sys

Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Type checker test cases"""

from __future__ import annotations

import os
import re
import sys
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
whole tree.
"""

from __future__ import annotations

import os
import re
import subprocess
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testconstraints.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from mypy.constraints import SUBTYPE_OF, SUPERTYPE_OF, Constraint, infer_constraints
from mypy.test.helpers import Suite
from mypy.test.typefixture import TypeFixture
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
This also includes some unit tests.
"""

from __future__ import annotations

import os
import subprocess
import sys
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testdeps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test cases for generating node-level dependencies (for fine-grained incremental checking)"""

from __future__ import annotations

import os
from collections import defaultdict
from typing import DefaultDict, Dict, List, Optional, Set, Tuple
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testdiff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test cases for AST diff (used for fine-grained incremental checking)"""

from __future__ import annotations

import os
from typing import Dict, List, Optional, Tuple

Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testerrorstream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Tests for mypy incremental error output."""
from __future__ import annotations

from typing import List

from mypy import build
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testfinegrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
on specified sources.
"""

from __future__ import annotations

import os
import re
import sys
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testfinegrainedcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

# We can't "import FineGrainedSuite from ..." because that will cause pytest
# to collect the non-caching tests when running this file.
from __future__ import annotations

import mypy.test.testfinegrained


Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testformatter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from unittest import TestCase, main

from mypy.util import split_words, trim_source_line
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testfscache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Unit tests for file system cache."""

from __future__ import annotations

import os
import shutil
import sys
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testgraph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test cases for graph processing code in build.py."""

from __future__ import annotations

import sys
from typing import AbstractSet, Dict, List, Set

Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testinfer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test cases for type inference helper functions."""

from __future__ import annotations

from typing import Dict, List, Optional, Set, Tuple, Union

from mypy.argmap import map_actuals_to_formals
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testipc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import sys
import time
from multiprocessing import Process, Queue
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testmerge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test cases for AST merge (used for fine-grained incremental checking)"""

from __future__ import annotations

import os
import shutil
from typing import Dict, List, Optional, Tuple
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testmodulefinder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os

from mypy.modulefinder import FindModuleCache, ModuleNotFoundReason, SearchPaths
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testmypyc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""A basic check to make sure that we are using a mypyc-compiled version when expected."""

from __future__ import annotations

import os
from unittest import TestCase

Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testparse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests for the mypy parser."""

from __future__ import annotations

import sys

from pytest import skip
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testpep561.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import re
import subprocess
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testpythoneval.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
this suite would slow down the main suite too much.
"""

from __future__ import annotations

import os
import os.path
import re
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testreports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Test cases for reports generated by mypy."""
from __future__ import annotations

import textwrap

from mypy.report import CoberturaPackage, get_line_rate
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testsemanal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Semantic analyzer test cases"""

from __future__ import annotations

import os.path
import sys
from typing import Dict, List
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testsolve.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test cases for the constraint solver used in type inference."""

from __future__ import annotations

from typing import List, Optional, Tuple, Union

from mypy.constraints import SUBTYPE_OF, SUPERTYPE_OF, Constraint
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/teststubgen.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import io
import os.path
import re
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/teststubinfo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import unittest

from mypy.stubinfo import is_legacy_bundled_package
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import contextlib
import inspect
import io
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testsubtypes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from mypy.nodes import CONTRAVARIANT, COVARIANT, INVARIANT
from mypy.subtypes import is_subtype
from mypy.test.helpers import Suite, skip
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/testtransform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Identity AST transform test cases"""

from __future__ import annotations

import os.path

from mypy import build
Expand Down
Loading

0 comments on commit b1364c5

Please sign in to comment.