Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 694f283

Browse files
authored
Run pyupgrade on the source code (#13355)
1 parent e69bd9a commit 694f283

40 files changed

Lines changed: 149 additions & 170 deletions

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: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
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,
3133
List,
3234
Mapping,
3335
NamedTuple,
36+
NoReturn,
3437
Optional,
3538
Sequence,
3639
Set,
@@ -41,7 +44,7 @@
4144
)
4245

4346
from mypy_extensions import TypedDict
44-
from typing_extensions import TYPE_CHECKING, ClassVar, Final, NoReturn, TypeAlias as _TypeAlias
47+
from typing_extensions import Final, TypeAlias as _TypeAlias
4548

4649
import mypy.semanal_main
4750
from mypy.checker import TypeChecker
@@ -1068,9 +1071,7 @@ def read_plugins_snapshot(manager: BuildManager) -> Optional[Dict[str, str]]:
10681071
if snapshot is None:
10691072
return None
10701073
if not isinstance(snapshot, dict):
1071-
manager.log(
1072-
"Could not load plugins snapshot: cache is not a dict: {}".format(type(snapshot))
1073-
)
1074+
manager.log(f"Could not load plugins snapshot: cache is not a dict: {type(snapshot)}")
10741075
return None
10751076
return snapshot
10761077

@@ -1284,9 +1285,7 @@ def find_cache_meta(id: str, path: str, manager: BuildManager) -> Optional[Cache
12841285
if meta is None:
12851286
return None
12861287
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-
)
1288+
manager.log(f"Could not load cache for {id}: meta cache is not a dict: {repr(meta)}")
12901289
return None
12911290
m = cache_meta_from_dict(meta, data_json)
12921291
t2 = time.time()
@@ -1459,9 +1458,7 @@ def validate_meta(
14591458
manager.log(f"Using stale metadata for {id}: file {path}")
14601459
return meta
14611460
else:
1462-
manager.log(
1463-
"Metadata abandoned for {}: file {} has different hash".format(id, path)
1464-
)
1461+
manager.log(f"Metadata abandoned for {id}: file {path} has different hash")
14651462
return None
14661463
else:
14671464
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/dmypy/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import sys
1313
import time
1414
import traceback
15-
from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple
16-
17-
from typing_extensions import NoReturn
15+
from typing import Any, Callable, Dict, List, Mapping, NoReturn, Optional, Tuple
1816

1917
from mypy.dmypy_os import alive, kill
2018
from mypy.dmypy_util import DEFAULT_STATUS_FILE, receive

mypy/errors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import sys
33
import traceback
44
from collections import defaultdict
5-
from typing import Callable, Dict, List, Optional, Set, TextIO, Tuple, TypeVar, Union
5+
from typing import Callable, Dict, List, NoReturn, Optional, Set, TextIO, Tuple, TypeVar, Union
66

7-
from typing_extensions import Final, Literal, NoReturn
7+
from typing_extensions import Final, Literal
88

99
from mypy import errorcodes as codes
1010
from mypy.errorcodes import IMPORT, ErrorCode
@@ -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

0 commit comments

Comments
 (0)