Skip to content

Commit

Permalink
Run pyupgrade on the source code (#13355)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored Aug 8, 2022
1 parent e69bd9a commit 694f283
Show file tree
Hide file tree
Showing 40 changed files with 149 additions and 170 deletions.
4 changes: 2 additions & 2 deletions mypy/binder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections import defaultdict
from contextlib import contextmanager
from typing import Dict, Iterator, List, Optional, Set, Tuple, Union, cast
from typing import DefaultDict, Dict, Iterator, List, Optional, Set, Tuple, Union, cast

from typing_extensions import DefaultDict, TypeAlias as _TypeAlias
from typing_extensions import TypeAlias as _TypeAlias

from mypy.erasetype import remove_instance_last_known_values
from mypy.join import join_simple
Expand Down
17 changes: 7 additions & 10 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
import time
import types
from typing import (
TYPE_CHECKING,
AbstractSet,
Any,
Callable,
ClassVar,
Dict,
Iterable,
Iterator,
List,
Mapping,
NamedTuple,
NoReturn,
Optional,
Sequence,
Set,
Expand All @@ -41,7 +44,7 @@
)

from mypy_extensions import TypedDict
from typing_extensions import TYPE_CHECKING, ClassVar, Final, NoReturn, TypeAlias as _TypeAlias
from typing_extensions import Final, TypeAlias as _TypeAlias

import mypy.semanal_main
from mypy.checker import TypeChecker
Expand Down Expand Up @@ -1068,9 +1071,7 @@ def read_plugins_snapshot(manager: BuildManager) -> Optional[Dict[str, str]]:
if snapshot is None:
return None
if not isinstance(snapshot, dict):
manager.log(
"Could not load plugins snapshot: cache is not a dict: {}".format(type(snapshot))
)
manager.log(f"Could not load plugins snapshot: cache is not a dict: {type(snapshot)}")
return None
return snapshot

Expand Down Expand Up @@ -1284,9 +1285,7 @@ def find_cache_meta(id: str, path: str, manager: BuildManager) -> Optional[Cache
if meta is None:
return None
if not isinstance(meta, dict):
manager.log(
"Could not load cache for {}: meta cache is not a dict: {}".format(id, repr(meta))
)
manager.log(f"Could not load cache for {id}: meta cache is not a dict: {repr(meta)}")
return None
m = cache_meta_from_dict(meta, data_json)
t2 = time.time()
Expand Down Expand Up @@ -1459,9 +1458,7 @@ def validate_meta(
manager.log(f"Using stale metadata for {id}: file {path}")
return meta
else:
manager.log(
"Metadata abandoned for {}: file {} has different hash".format(id, path)
)
manager.log(f"Metadata abandoned for {id}: file {path} has different hash")
return None
else:
t0 = time.time()
Expand Down
16 changes: 14 additions & 2 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

import itertools
from contextlib import contextmanager
from typing import Callable, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Union, cast
from typing import (
Callable,
ClassVar,
Dict,
Iterator,
List,
Optional,
Sequence,
Set,
Tuple,
Union,
cast,
)

from typing_extensions import ClassVar, Final, TypeAlias as _TypeAlias, overload
from typing_extensions import Final, TypeAlias as _TypeAlias, overload

import mypy.checker
import mypy.errorcodes as codes
Expand Down
6 changes: 2 additions & 4 deletions mypy/checkmember.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Type checking of attribute access"""

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

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

from mypy import meet, message_registry, subtypes
from mypy.erasetype import erase_typevars
Expand Down Expand Up @@ -836,7 +834,7 @@ def analyze_class_attribute_access(
if override_info:
info = override_info

fullname = "{}.{}".format(info.fullname, name)
fullname = f"{info.fullname}.{name}"
hook = mx.chk.plugin.get_class_attribute_hook(fullname)

node = info.get(name)
Expand Down
16 changes: 14 additions & 2 deletions mypy/checkstrformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@
"""

import re
from typing import Callable, Dict, List, Match, Optional, Pattern, Set, Tuple, Union, cast
from typing import (
TYPE_CHECKING,
Callable,
Dict,
List,
Match,
Optional,
Pattern,
Set,
Tuple,
Union,
cast,
)

from typing_extensions import TYPE_CHECKING, Final, TypeAlias as _TypeAlias
from typing_extensions import Final, TypeAlias as _TypeAlias

import mypy.errorcodes as codes
from mypy.errors import Errors
Expand Down
2 changes: 1 addition & 1 deletion mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def parse_version(v: Union[str, float]) -> Tuple[int, int]:
pass # Error raised elsewhere
elif major == 3:
if minor < defaults.PYTHON3_VERSION_MIN[1]:
msg = "Python 3.{0} is not supported (must be {1}.{2} or higher)".format(
msg = "Python 3.{} is not supported (must be {}.{} or higher)".format(
minor, *defaults.PYTHON3_VERSION_MIN
)

Expand Down
4 changes: 1 addition & 3 deletions mypy/dmypy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import sys
import time
import traceback
from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple

from typing_extensions import NoReturn
from typing import Any, Callable, Dict, List, Mapping, NoReturn, Optional, Tuple

from mypy.dmypy_os import alive, kill
from mypy.dmypy_util import DEFAULT_STATUS_FILE, receive
Expand Down
8 changes: 4 additions & 4 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import sys
import traceback
from collections import defaultdict
from typing import Callable, Dict, List, Optional, Set, TextIO, Tuple, TypeVar, Union
from typing import Callable, Dict, List, NoReturn, Optional, Set, TextIO, Tuple, TypeVar, Union

from typing_extensions import Final, Literal, NoReturn
from typing_extensions import Final, Literal

from mypy import errorcodes as codes
from mypy.errorcodes import IMPORT, ErrorCode
Expand Down Expand Up @@ -884,7 +884,7 @@ def render_messages(self, errors: List[ErrorInfo]) -> List[ErrorTuple]:
-1,
-1,
"note",
'In class "{}":'.format(e.type),
f'In class "{e.type}":',
e.allow_dups,
None,
)
Expand All @@ -899,7 +899,7 @@ def render_messages(self, errors: List[ErrorInfo]) -> List[ErrorTuple]:
-1,
-1,
"note",
'In function "{}":'.format(e.function_or_member),
f'In function "{e.function_or_member}":',
e.allow_dups,
None,
)
Expand Down
4 changes: 1 addition & 3 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1855,9 +1855,7 @@ def _extract_argument_name(self, n: ast3.expr) -> Optional[str]:
elif isinstance(n, NameConstant) and str(n.value) == "None":
return None
self.fail(
"Expected string literal for argument name, got {}".format(type(n).__name__),
self.line,
0,
f"Expected string literal for argument name, got {type(n).__name__}", self.line, 0
)
return None

Expand Down
4 changes: 2 additions & 2 deletions mypy/ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import sys
import tempfile
from types import TracebackType
from typing import Callable, Optional
from typing import Callable, Optional, Type

from typing_extensions import Final, Type
from typing_extensions import Final

if sys.platform == "win32":
# This may be private, but it is needed for IPC on Windows, and is basically stable
Expand Down
4 changes: 2 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import sys
import time
from gettext import gettext
from typing import IO, Any, Dict, List, Optional, Sequence, TextIO, Tuple, Union
from typing import IO, Any, Dict, List, NoReturn, Optional, Sequence, TextIO, Tuple, Union

from typing_extensions import Final, NoReturn
from typing_extensions import Final

from mypy import build, defaults, state, util
from mypy.config_parser import get_config_module_names, parse_config_file, parse_version
Expand Down
Loading

0 comments on commit 694f283

Please sign in to comment.