Skip to content

Commit 329441f

Browse files
committed
Run pyupgrade on the source code
1 parent ae2fc03 commit 329441f

38 files changed

+141
-154
lines changed

mypy/binder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from collections import defaultdict
22
from contextlib import contextmanager
3-
from typing import Dict, Iterator, List, Optional, Set, Tuple, Union, cast
3+
from typing import DefaultDict, Dict, Iterator, List, Optional, Set, Tuple, Union, cast
44

5-
from typing_extensions import DefaultDict, TypeAlias as _TypeAlias
5+
from typing_extensions import TypeAlias as _TypeAlias
66

77
from mypy.erasetype import remove_instance_last_known_values
88
from mypy.join import join_simple

mypy/build.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import time
2323
import types
2424
from typing import (
25+
TYPE_CHECKING,
2526
AbstractSet,
2627
Any,
2728
Callable,
29+
ClassVar,
2830
Dict,
2931
Iterable,
3032
Iterator,
@@ -41,7 +43,7 @@
4143
)
4244

4345
from mypy_extensions import TypedDict
44-
from typing_extensions import TYPE_CHECKING, ClassVar, Final, NoReturn, TypeAlias as _TypeAlias
46+
from typing_extensions import Final, NoReturn, TypeAlias as _TypeAlias
4547

4648
import mypy.semanal_main
4749
from mypy.checker import TypeChecker
@@ -1068,9 +1070,7 @@ def read_plugins_snapshot(manager: BuildManager) -> Optional[Dict[str, str]]:
10681070
if snapshot is None:
10691071
return None
10701072
if not isinstance(snapshot, dict):
1071-
manager.log(
1072-
"Could not load plugins snapshot: cache is not a dict: {}".format(type(snapshot))
1073-
)
1073+
manager.log(f"Could not load plugins snapshot: cache is not a dict: {type(snapshot)}")
10741074
return None
10751075
return snapshot
10761076

@@ -1284,9 +1284,7 @@ def find_cache_meta(id: str, path: str, manager: BuildManager) -> Optional[Cache
12841284
if meta is None:
12851285
return None
12861286
if not isinstance(meta, dict):
1287-
manager.log(
1288-
"Could not load cache for {}: meta cache is not a dict: {}".format(id, repr(meta))
1289-
)
1287+
manager.log(f"Could not load cache for {id}: meta cache is not a dict: {repr(meta)}")
12901288
return None
12911289
m = cache_meta_from_dict(meta, data_json)
12921290
t2 = time.time()
@@ -1459,9 +1457,7 @@ def validate_meta(
14591457
manager.log(f"Using stale metadata for {id}: file {path}")
14601458
return meta
14611459
else:
1462-
manager.log(
1463-
"Metadata abandoned for {}: file {} has different hash".format(id, path)
1464-
)
1460+
manager.log(f"Metadata abandoned for {id}: file {path} has different hash")
14651461
return None
14661462
else:
14671463
t0 = time.time()

mypy/checkexpr.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,21 @@
22

33
import itertools
44
from contextlib import contextmanager
5-
from typing import Callable, Dict, Iterator, List, Optional, Sequence, Set, Tuple, Union, cast
5+
from typing import (
6+
Callable,
7+
ClassVar,
8+
Dict,
9+
Iterator,
10+
List,
11+
Optional,
12+
Sequence,
13+
Set,
14+
Tuple,
15+
Union,
16+
cast,
17+
)
618

7-
from typing_extensions import ClassVar, Final, TypeAlias as _TypeAlias, overload
19+
from typing_extensions import Final, TypeAlias as _TypeAlias, overload
820

921
import mypy.checker
1022
import mypy.errorcodes as codes

mypy/checkmember.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""Type checking of attribute access"""
22

3-
from typing import Callable, Optional, Sequence, Union, cast
4-
5-
from typing_extensions import TYPE_CHECKING
3+
from typing import TYPE_CHECKING, Callable, Optional, Sequence, Union, cast
64

75
from mypy import meet, message_registry, subtypes
86
from mypy.erasetype import erase_typevars
@@ -836,7 +834,7 @@ def analyze_class_attribute_access(
836834
if override_info:
837835
info = override_info
838836

839-
fullname = "{}.{}".format(info.fullname, name)
837+
fullname = f"{info.fullname}.{name}"
840838
hook = mx.chk.plugin.get_class_attribute_hook(fullname)
841839

842840
node = info.get(name)

mypy/checkstrformat.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,21 @@
1111
"""
1212

1313
import re
14-
from typing import Callable, Dict, List, Match, Optional, Pattern, Set, Tuple, Union, cast
14+
from typing import (
15+
TYPE_CHECKING,
16+
Callable,
17+
Dict,
18+
List,
19+
Match,
20+
Optional,
21+
Pattern,
22+
Set,
23+
Tuple,
24+
Union,
25+
cast,
26+
)
1527

16-
from typing_extensions import TYPE_CHECKING, Final, TypeAlias as _TypeAlias
28+
from typing_extensions import Final, TypeAlias as _TypeAlias
1729

1830
import mypy.errorcodes as codes
1931
from mypy.errors import Errors

mypy/config_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def parse_version(v: Union[str, float]) -> Tuple[int, int]:
4646
pass # Error raised elsewhere
4747
elif major == 3:
4848
if minor < defaults.PYTHON3_VERSION_MIN[1]:
49-
msg = "Python 3.{0} is not supported (must be {1}.{2} or higher)".format(
49+
msg = "Python 3.{} is not supported (must be {}.{} or higher)".format(
5050
minor, *defaults.PYTHON3_VERSION_MIN
5151
)
5252

mypy/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ def render_messages(self, errors: List[ErrorInfo]) -> List[ErrorTuple]:
884884
-1,
885885
-1,
886886
"note",
887-
'In class "{}":'.format(e.type),
887+
f'In class "{e.type}":',
888888
e.allow_dups,
889889
None,
890890
)
@@ -899,7 +899,7 @@ def render_messages(self, errors: List[ErrorInfo]) -> List[ErrorTuple]:
899899
-1,
900900
-1,
901901
"note",
902-
'In function "{}":'.format(e.function_or_member),
902+
f'In function "{e.function_or_member}":',
903903
e.allow_dups,
904904
None,
905905
)

mypy/fastparse.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,9 +1855,7 @@ def _extract_argument_name(self, n: ast3.expr) -> Optional[str]:
18551855
elif isinstance(n, NameConstant) and str(n.value) == "None":
18561856
return None
18571857
self.fail(
1858-
"Expected string literal for argument name, got {}".format(type(n).__name__),
1859-
self.line,
1860-
0,
1858+
f"Expected string literal for argument name, got {type(n).__name__}", self.line, 0
18611859
)
18621860
return None
18631861

mypy/ipc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import sys
1111
import tempfile
1212
from types import TracebackType
13-
from typing import Callable, Optional
13+
from typing import Callable, Optional, Type
1414

15-
from typing_extensions import Final, Type
15+
from typing_extensions import Final
1616

1717
if sys.platform == "win32":
1818
# This may be private, but it is needed for IPC on Windows, and is basically stable

mypy/messages.py

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def has_no_attr(
337337
self.fail(f'Member "{member}" is not assignable', context)
338338
elif member == "__contains__":
339339
self.fail(
340-
"Unsupported right operand type for in ({})".format(format_type(original_type)),
340+
f"Unsupported right operand type for in ({format_type(original_type)})",
341341
context,
342342
code=codes.OPERATOR,
343343
)
@@ -350,19 +350,19 @@ def has_no_attr(
350350
break
351351
elif member == "__neg__":
352352
self.fail(
353-
"Unsupported operand type for unary - ({})".format(format_type(original_type)),
353+
f"Unsupported operand type for unary - ({format_type(original_type)})",
354354
context,
355355
code=codes.OPERATOR,
356356
)
357357
elif member == "__pos__":
358358
self.fail(
359-
"Unsupported operand type for unary + ({})".format(format_type(original_type)),
359+
f"Unsupported operand type for unary + ({format_type(original_type)})",
360360
context,
361361
code=codes.OPERATOR,
362362
)
363363
elif member == "__invert__":
364364
self.fail(
365-
"Unsupported operand type for ~ ({})".format(format_type(original_type)),
365+
f"Unsupported operand type for ~ ({format_type(original_type)})",
366366
context,
367367
code=codes.OPERATOR,
368368
)
@@ -378,7 +378,7 @@ def has_no_attr(
378378
)
379379
else:
380380
self.fail(
381-
"Value of type {} is not indexable".format(format_type(original_type)),
381+
f"Value of type {format_type(original_type)} is not indexable",
382382
context,
383383
code=codes.INDEX,
384384
)
@@ -986,13 +986,13 @@ def no_variant_matches_arguments(
986986
)
987987
elif num_args == 1:
988988
self.fail(
989-
"No overload variant{} matches argument type {}".format(name_str, arg_types_str),
989+
f"No overload variant{name_str} matches argument type {arg_types_str}",
990990
context,
991991
code=code,
992992
)
993993
else:
994994
self.fail(
995-
"No overload variant{} matches argument types {}".format(name_str, arg_types_str),
995+
f"No overload variant{name_str} matches argument types {arg_types_str}",
996996
context,
997997
code=code,
998998
)
@@ -1009,13 +1009,11 @@ def wrong_number_values_to_unpack(
10091009
self.fail(f"Need more than 1 value to unpack ({expected} expected)", context)
10101010
else:
10111011
self.fail(
1012-
"Need more than {} values to unpack ({} expected)".format(provided, expected),
1013-
context,
1012+
f"Need more than {provided} values to unpack ({expected} expected)", context
10141013
)
10151014
elif provided > expected:
10161015
self.fail(
1017-
"Too many values to unpack ({} expected, {} provided)".format(expected, provided),
1018-
context,
1016+
f"Too many values to unpack ({expected} expected, {provided} provided)", context
10191017
)
10201018

10211019
def unpacking_strings_disallowed(self, context: Context) -> None:
@@ -1035,9 +1033,7 @@ def overload_signature_incompatible_with_supertype(
10351033
) -> None:
10361034
target = self.override_target(name, name_in_super, supertype)
10371035
self.fail(
1038-
'Signature of "{}" incompatible with {}'.format(name, target),
1039-
context,
1040-
code=codes.OVERRIDE,
1036+
f'Signature of "{name}" incompatible with {target}', context, code=codes.OVERRIDE
10411037
)
10421038

10431039
note_template = 'Overload variants must be defined in the same order as they are in "{}"'
@@ -1054,9 +1050,7 @@ def signature_incompatible_with_supertype(
10541050
) -> None:
10551051
code = codes.OVERRIDE
10561052
target = self.override_target(name, name_in_super, supertype)
1057-
self.fail(
1058-
'Signature of "{}" incompatible with {}'.format(name, target), context, code=code
1059-
)
1053+
self.fail(f'Signature of "{name}" incompatible with {target}', context, code=code)
10601054

10611055
INCLUDE_DECORATOR = True # Include @classmethod and @staticmethod decorators, if any
10621056
ALLOW_DUPS = True # Allow duplicate notes, needed when signatures are duplicates
@@ -1197,13 +1191,11 @@ def incompatible_type_application(
11971191
self.fail("Type application targets a non-generic function or class", context)
11981192
elif actual_arg_count > expected_arg_count:
11991193
self.fail(
1200-
"Type application has too many types ({} expected)".format(expected_arg_count),
1201-
context,
1194+
f"Type application has too many types ({expected_arg_count} expected)", context
12021195
)
12031196
else:
12041197
self.fail(
1205-
"Type application has too few types ({} expected)".format(expected_arg_count),
1206-
context,
1198+
f"Type application has too few types ({expected_arg_count} expected)", context
12071199
)
12081200

12091201
def could_not_infer_type_arguments(
@@ -1487,9 +1479,7 @@ def forward_operator_not_callable(self, forward_method: str, context: Context) -
14871479
self.fail(f'Forward operator "{forward_method}" is not callable', context)
14881480

14891481
def signatures_incompatible(self, method: str, other_method: str, context: Context) -> None:
1490-
self.fail(
1491-
'Signatures of "{}" and "{}" are incompatible'.format(method, other_method), context
1492-
)
1482+
self.fail(f'Signatures of "{method}" and "{other_method}" are incompatible', context)
14931483

14941484
def yield_from_invalid_operand_type(self, expr: Type, context: Context) -> Type:
14951485
text = format_type(expr) if format_type(expr) != "object" else expr
@@ -1641,7 +1631,7 @@ def typeddict_key_not_found(
16411631
)
16421632
else:
16431633
self.fail(
1644-
'TypedDict {} has no key "{}"'.format(format_type(typ), item_name),
1634+
f'TypedDict {format_type(typ)} has no key "{item_name}"',
16451635
context,
16461636
code=codes.TYPEDDICT_ITEM,
16471637
)
@@ -1655,9 +1645,7 @@ def typeddict_key_not_found(
16551645

16561646
def typeddict_context_ambiguous(self, types: List[TypedDictType], context: Context) -> None:
16571647
formatted_types = ", ".join(list(format_type_distinctly(*types)))
1658-
self.fail(
1659-
"Type of TypedDict is ambiguous, could be any of ({})".format(formatted_types), context
1660-
)
1648+
self.fail(f"Type of TypedDict is ambiguous, could be any of ({formatted_types})", context)
16611649

16621650
def typeddict_key_cannot_be_deleted(
16631651
self, typ: TypedDictType, item_name: str, context: Context
@@ -1666,8 +1654,7 @@ def typeddict_key_cannot_be_deleted(
16661654
self.fail(f'TypedDict key "{item_name}" cannot be deleted', context)
16671655
else:
16681656
self.fail(
1669-
'Key "{}" of TypedDict {} cannot be deleted'.format(item_name, format_type(typ)),
1670-
context,
1657+
f'Key "{item_name}" of TypedDict {format_type(typ)} cannot be deleted', context
16711658
)
16721659

16731660
def typeddict_setdefault_arguments_inconsistent(
@@ -1719,8 +1706,7 @@ def untyped_decorated_function(self, typ: Type, context: Context) -> None:
17191706
self.fail("Function is untyped after decorator transformation", context)
17201707
else:
17211708
self.fail(
1722-
'Type of decorated function contains type "Any" ({})'.format(format_type(typ)),
1723-
context,
1709+
f'Type of decorated function contains type "Any" ({format_type(typ)})', context
17241710
)
17251711

17261712
def typed_function_untyped_decorator(self, func_name: str, context: Context) -> None:
@@ -1739,14 +1725,12 @@ def bad_proto_variance(
17391725

17401726
def concrete_only_assign(self, typ: Type, context: Context) -> None:
17411727
self.fail(
1742-
"Can only assign concrete classes to a variable of type {}".format(format_type(typ)),
1743-
context,
1728+
f"Can only assign concrete classes to a variable of type {format_type(typ)}", context
17441729
)
17451730

17461731
def concrete_only_call(self, typ: Type, context: Context) -> None:
17471732
self.fail(
1748-
"Only concrete class can be given where {} is expected".format(format_type(typ)),
1749-
context,
1733+
f"Only concrete class can be given where {format_type(typ)} is expected", context
17501734
)
17511735

17521736
def cannot_use_function_with_type(
@@ -1763,7 +1747,7 @@ def report_non_method_protocol(
17631747
)
17641748
if len(members) < 3:
17651749
attrs = ", ".join(members)
1766-
self.note('Protocol "{}" has non-method member(s): {}'.format(tp.name, attrs), context)
1750+
self.note(f'Protocol "{tp.name}" has non-method member(s): {attrs}', context)
17671751

17681752
def note_call(
17691753
self, subtype: Type, call: Type, context: Context, *, code: Optional[ErrorCode]
@@ -2117,9 +2101,7 @@ def format_callable_args(
21172101
if arg_kind.is_star() or arg_name is None:
21182102
arg_strings.append(f"{constructor}({format(arg_type)})")
21192103
else:
2120-
arg_strings.append(
2121-
"{}({}, {})".format(constructor, format(arg_type), repr(arg_name))
2122-
)
2104+
arg_strings.append(f"{constructor}({format(arg_type)}, {repr(arg_name)})")
21232105

21242106
return ", ".join(arg_strings)
21252107

mypy/metastore.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import os
1313
import time
1414
from abc import abstractmethod
15-
from typing import Any, Iterable, List, Optional
16-
17-
from typing_extensions import TYPE_CHECKING
15+
from typing import TYPE_CHECKING, Any, Iterable, List, Optional
1816

1917
if TYPE_CHECKING:
2018
# We avoid importing sqlite3 unless we are using it so we can mostly work

0 commit comments

Comments
 (0)