Skip to content

Commit 4276308

Browse files
authored
(🎁) update black to 23.3.0 (#15059)
Co-authored-by: KotlinIsland <[email protected]>
1 parent 1449366 commit 4276308

36 files changed

+55
-67
lines changed

Diff for: .pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 22.12.0 # must match test-requirements.txt
3+
rev: 23.3.0 # must match test-requirements.txt
44
hooks:
55
- id: black
66
- repo: https://github.com/pycqa/isort

Diff for: misc/analyze_cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def load_json(data_path: str, meta_path: str) -> CacheData:
6262

6363

6464
def get_files(root: str) -> Iterable[CacheData]:
65-
for (dirpath, dirnames, filenames) in os.walk(root):
65+
for dirpath, dirnames, filenames in os.walk(root):
6666
for filename in filenames:
6767
if filename.endswith(".data.json"):
6868
meta_filename = filename.replace(".data.json", ".meta.json")

Diff for: misc/fix_annotate.py

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def foo(self, bar, baz=12):
3838

3939

4040
class FixAnnotate(BaseFix):
41-
4241
# This fixer is compatible with the bottom matcher.
4342
BM_compatible = True
4443

Diff for: mypy/api.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151

5252

5353
def _run(main_wrapper: Callable[[TextIO, TextIO], None]) -> tuple[str, str, int]:
54-
5554
stdout = StringIO()
5655
stderr = StringIO()
5756

Diff for: mypy/checker.py

-2
Original file line numberDiff line numberDiff line change
@@ -2068,7 +2068,6 @@ def erase_override(t: Type) -> Type:
20682068
if not is_subtype(
20692069
original.arg_types[i], erase_override(override.arg_types[i])
20702070
):
2071-
20722071
arg_type_in_super = original.arg_types[i]
20732072

20742073
if isinstance(node, FuncDef):
@@ -2954,7 +2953,6 @@ def check_compatibility_all_supers(
29542953
and lvalue.kind in (MDEF, None)
29552954
and len(lvalue_node.info.bases) > 0 # None for Vars defined via self
29562955
):
2957-
29582956
for base in lvalue_node.info.mro[1:]:
29592957
tnode = base.names.get(lvalue_node.name)
29602958
if tnode is not None:

Diff for: mypy/checkexpr.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
# Type of callback user for checking individual function arguments. See
171171
# check_args() below for details.
172172
ArgChecker: _TypeAlias = Callable[
173-
[Type, Type, ArgKind, Type, int, int, CallableType, Optional[Type], Context, Context], None,
173+
[Type, Type, ArgKind, Type, int, int, CallableType, Optional[Type], Context, Context], None
174174
]
175175

176176
# Maximum nesting level for math union in overloads, setting this to large values
@@ -845,7 +845,7 @@ def check_typeddict_call_with_kwargs(
845845
# this may give a better error message.
846846
ret_type = callee
847847

848-
for (item_name, item_expected_type) in ret_type.items.items():
848+
for item_name, item_expected_type in ret_type.items.items():
849849
if item_name in kwargs:
850850
item_value = kwargs[item_name]
851851
self.chk.check_simple_assignment(

Diff for: mypy/checkstrformat.py

-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ class ConversionSpecifier:
139139
def __init__(
140140
self, match: Match[str], start_pos: int = -1, non_standard_format_spec: bool = False
141141
) -> None:
142-
143142
self.whole_seq = match.group()
144143
self.start_pos = start_pos
145144

Diff for: mypy/config_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from mypy.options import PER_MODULE_OPTIONS, Options
3535

3636
_CONFIG_VALUE_TYPES: _TypeAlias = Union[
37-
str, bool, int, float, Dict[str, str], List[str], Tuple[int, int],
37+
str, bool, int, float, Dict[str, str], List[str], Tuple[int, int]
3838
]
3939
_INI_PARSER_CALLABLE: _TypeAlias = Callable[[Any], _CONFIG_VALUE_TYPES]
4040

Diff for: mypy/constraints.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,6 @@ def infer_against_overloaded(
10061006
return infer_constraints(template, item, self.direction)
10071007

10081008
def visit_tuple_type(self, template: TupleType) -> list[Constraint]:
1009-
10101009
actual = self.actual
10111010
unpack_index = find_unpack_in_list(template.items)
10121011
is_varlength_tuple = (
@@ -1065,7 +1064,7 @@ def visit_typeddict_type(self, template: TypedDictType) -> list[Constraint]:
10651064
res: list[Constraint] = []
10661065
# NOTE: Non-matching keys are ignored. Compatibility is checked
10671066
# elsewhere so this shouldn't be unsafe.
1068-
for (item_name, template_item_type, actual_item_type) in template.zip(actual):
1067+
for item_name, template_item_type, actual_item_type in template.zip(actual):
10691068
res.extend(infer_constraints(template_item_type, actual_item_type, self.direction))
10701069
return res
10711070
elif isinstance(actual, AnyType):

Diff for: mypy/dmypy_server.py

-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ def ignore_suppressed_imports(module: str) -> bool:
163163

164164

165165
class Server:
166-
167166
# NOTE: the instance is constructed in the parent process but
168167
# serve() is called in the grandchild (by daemonize()).
169168

@@ -828,7 +827,6 @@ def update_sources(self, sources: list[BuildSource]) -> None:
828827
def update_changed(
829828
self, sources: list[BuildSource], remove: list[str], update: list[str]
830829
) -> ChangesAndRemovals:
831-
832830
changed_paths = self.fswatcher.update_changed(remove, update)
833831
return self._find_changed(sources, changed_paths)
834832

Diff for: mypy/fastparse.py

-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ def parse(
255255
errors: Errors | None = None,
256256
options: Options | None = None,
257257
) -> MypyFile:
258-
259258
"""Parse a source file, without doing any semantic analysis.
260259
261260
Return the parse tree. If errors is not provided, raise ParseError

Diff for: mypy/ipc.py

-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ def __exit__(
169169

170170

171171
class IPCServer(IPCBase):
172-
173172
BUFFER_SIZE: Final = 2**16
174173

175174
def __init__(self, name: str, timeout: float | None = None) -> None:

Diff for: mypy/meet.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -828,13 +828,13 @@ def visit_tuple_type(self, t: TupleType) -> ProperType:
828828

829829
def visit_typeddict_type(self, t: TypedDictType) -> ProperType:
830830
if isinstance(self.s, TypedDictType):
831-
for (name, l, r) in self.s.zip(t):
831+
for name, l, r in self.s.zip(t):
832832
if not is_equivalent(l, r) or (name in t.required_keys) != (
833833
name in self.s.required_keys
834834
):
835835
return self.default(self.s)
836836
item_list: list[tuple[str, Type]] = []
837-
for (item_name, s_item_type, t_item_type) in self.s.zipall(t):
837+
for item_name, s_item_type, t_item_type in self.s.zipall(t):
838838
if s_item_type is not None:
839839
item_list.append((item_name, s_item_type))
840840
else:

Diff for: mypy/messages.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,6 @@ def format_callable_args(
22762276
arg_strings = []
22772277
for arg_name, arg_type, arg_kind in zip(arg_names, arg_types, arg_kinds):
22782278
if arg_kind == ARG_POS and arg_name is None or verbosity == 0 and arg_kind.is_positional():
2279-
22802279
arg_strings.append(format(arg_type))
22812280
else:
22822281
constructor = ARG_CONSTRUCTOR_NAMES[arg_kind]
@@ -2383,7 +2382,7 @@ def format_literal_value(typ: LiteralType) -> str:
23832382
if not typ.is_anonymous():
23842383
return format(typ.fallback)
23852384
items = []
2386-
for (item_name, item_type) in typ.items.items():
2385+
for item_name, item_type in typ.items.items():
23872386
modifier = "" if item_name in typ.required_keys else "?"
23882387
items.append(f"{item_name!r}{modifier}: {format(item_type)}")
23892388
s = f"TypedDict({{{', '.join(items)}}})"

Diff for: mypy/nodes.py

-1
Original file line numberDiff line numberDiff line change
@@ -3326,7 +3326,6 @@ def deserialize(cls, data: JsonDict) -> TypeInfo:
33263326

33273327

33283328
class FakeInfo(TypeInfo):
3329-
33303329
__slots__ = ("msg",)
33313330

33323331
# types.py defines a single instance of this class, called types.NOT_READY.

Diff for: mypy/plugins/attrs.py

-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,6 @@ def _cleanup_decorator(stmt: Decorator, attr_map: dict[str, Attribute]) -> None:
529529
and isinstance(func_decorator.expr, NameExpr)
530530
and func_decorator.expr.name in attr_map
531531
):
532-
533532
if func_decorator.name == "default":
534533
attr_map[func_decorator.expr.name].has_default = True
535534

Diff for: mypy/plugins/dataclasses.py

-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ def transform(self) -> bool:
220220
and ("__init__" not in info.names or info.names["__init__"].plugin_generated)
221221
and attributes
222222
):
223-
224223
with state.strict_optional_set(self._api.options.strict_optional):
225224
args = [
226225
attr.to_argument(info)

Diff for: mypy/plugins/singledispatch.py

-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def create_singledispatch_function_callback(ctx: FunctionContext) -> Type:
9999
"""Called for functools.singledispatch"""
100100
func_type = get_proper_type(get_first_arg(ctx.arg_types))
101101
if isinstance(func_type, CallableType):
102-
103102
if len(func_type.arg_kinds) < 1:
104103
fail(
105104
ctx, "Singledispatch function requires at least one argument", func_type.definition
@@ -176,7 +175,6 @@ def register_function(
176175

177176
fallback_dispatch_type = fallback.arg_types[0]
178177
if not is_subtype(dispatch_type, fallback_dispatch_type):
179-
180178
fail(
181179
ctx,
182180
"Dispatch type {} must be subtype of fallback function first argument {}".format(

Diff for: mypy/report.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
)
4545

4646
ReporterClasses: _TypeAlias = Dict[
47-
str, Tuple[Callable[["Reports", str], "AbstractReporter"], bool],
47+
str, Tuple[Callable[["Reports", str], "AbstractReporter"], bool]
4848
]
4949

5050
reporter_classes: Final[ReporterClasses] = {}
@@ -860,7 +860,6 @@ def on_file(
860860
type_map: dict[Expression, Type],
861861
options: Options,
862862
) -> None:
863-
864863
try:
865864
path = os.path.relpath(tree.path)
866865
except ValueError:

Diff for: mypy/semanal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ def prepare_typing_namespace(self, file_node: MypyFile, aliases: dict[str, str])
510510
511511
They will be replaced with real aliases when corresponding targets are ready.
512512
"""
513+
513514
# This is all pretty unfortunate. typeshed now has a
514515
# sys.version_info check for OrderedDict, and we shouldn't
515516
# take it out, because it is correct and a typechecker should
@@ -4422,7 +4423,6 @@ def process__slots__(self, s: AssignmentStmt) -> None:
44224423
and s.lvalues[0].name == "__slots__"
44234424
and s.lvalues[0].kind == MDEF
44244425
):
4425-
44264426
# We understand `__slots__` defined as string, tuple, list, set, and dict:
44274427
if not isinstance(s.rvalue, (StrExpr, ListExpr, TupleExpr, SetExpr, DictExpr)):
44284428
# For example, `__slots__` can be defined as a variable,

Diff for: mypy/semanal_typeddict.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def parse_typeddict_fields_with_types(
469469
seen_keys = set()
470470
items: list[str] = []
471471
types: list[Type] = []
472-
for (field_name_expr, field_type_expr) in dict_items:
472+
for field_name_expr, field_type_expr in dict_items:
473473
if isinstance(field_name_expr, StrExpr):
474474
key = field_name_expr.value
475475
items.append(key)

Diff for: mypy/subtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ def f(self) -> A: ...
10341034
if not members_right.issubset(members_left):
10351035
return False
10361036
assuming = right.type.assuming_proper if proper_subtype else right.type.assuming
1037-
for (l, r) in reversed(assuming):
1037+
for l, r in reversed(assuming):
10381038
if l == left and r == right:
10391039
return True
10401040
with pop_on_exit(assuming, left, right):

Diff for: mypy/test/teststubgen.py

+4
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ def test(self, arg0: str = "") -> None:
10611061

10621062
def test_generate_c_function_other_module_arg(self) -> None:
10631063
"""Test that if argument references type from other module, module will be imported."""
1064+
10641065
# Provide different type in python spec than in docstring to make sure, that docstring
10651066
# information is used.
10661067
def test(arg0: str) -> None:
@@ -1087,6 +1088,7 @@ def test_generate_c_function_same_module(self) -> None:
10871088
"""Test that if annotation references type from same module but using full path, no module
10881089
will be imported, and type specification will be striped to local reference.
10891090
"""
1091+
10901092
# Provide different type in python spec than in docstring to make sure, that docstring
10911093
# information is used.
10921094
def test(arg0: str) -> None:
@@ -1136,6 +1138,7 @@ def test_generate_c_function_same_module_nested(self) -> None:
11361138
"""Test that if annotation references type from same module but using full path, no module
11371139
will be imported, and type specification will be stripped to local reference.
11381140
"""
1141+
11391142
# Provide different type in python spec than in docstring to make sure, that docstring
11401143
# information is used.
11411144
def test(arg0: str) -> None:
@@ -1162,6 +1165,7 @@ def test_generate_c_function_same_module_compound(self) -> None:
11621165
"""Test that if annotation references type from same module but using full path, no module
11631166
will be imported, and type specification will be stripped to local reference.
11641167
"""
1168+
11651169
# Provide different type in python spec than in docstring to make sure, that docstring
11661170
# information is used.
11671171
def test(arg0: str) -> None:

Diff for: mypy/types.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ def is_meta_var(self) -> bool:
505505

506506

507507
class TypeVarLikeType(ProperType):
508-
509508
__slots__ = ("name", "fullname", "id", "upper_bound")
510509

511510
name: str # Name (may be qualified)
@@ -2406,17 +2405,17 @@ def names_are_wider_than(self, other: TypedDictType) -> bool:
24062405

24072406
def zip(self, right: TypedDictType) -> Iterable[tuple[str, Type, Type]]:
24082407
left = self
2409-
for (item_name, left_item_type) in left.items.items():
2408+
for item_name, left_item_type in left.items.items():
24102409
right_item_type = right.items.get(item_name)
24112410
if right_item_type is not None:
24122411
yield (item_name, left_item_type, right_item_type)
24132412

24142413
def zipall(self, right: TypedDictType) -> Iterable[tuple[str, Type | None, Type | None]]:
24152414
left = self
2416-
for (item_name, left_item_type) in left.items.items():
2415+
for item_name, left_item_type in left.items.items():
24172416
right_item_type = right.items.get(item_name)
24182417
yield (item_name, left_item_type, right_item_type)
2419-
for (item_name, right_item_type) in right.items.items():
2418+
for item_name, right_item_type in right.items.items():
24202419
if item_name in left.items:
24212420
continue
24222421
yield (item_name, None, right_item_type)

Diff for: mypy/typestate.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ def __init__(self) -> None:
112112
self.infer_unions = False
113113

114114
def is_assumed_subtype(self, left: Type, right: Type) -> bool:
115-
for (l, r) in reversed(self._assuming):
115+
for l, r in reversed(self._assuming):
116116
if get_proper_type(l) == get_proper_type(left) and get_proper_type(
117117
r
118118
) == get_proper_type(right):
119119
return True
120120
return False
121121

122122
def is_assumed_proper_subtype(self, left: Type, right: Type) -> bool:
123-
for (l, r) in reversed(self._assuming_proper):
123+
for l, r in reversed(self._assuming_proper):
124124
if get_proper_type(l) == get_proper_type(left) and get_proper_type(
125125
r
126126
) == get_proper_type(right):

Diff for: mypy/typevartuples.py

+26-20
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ def split_with_mapped_and_template(
5252
template: tuple[Type, ...],
5353
template_prefix_len: int,
5454
template_suffix_len: int,
55-
) -> tuple[
56-
tuple[Type, ...],
57-
tuple[Type, ...],
58-
tuple[Type, ...],
59-
tuple[Type, ...],
60-
tuple[Type, ...],
61-
tuple[Type, ...],
62-
] | None:
55+
) -> (
56+
tuple[
57+
tuple[Type, ...],
58+
tuple[Type, ...],
59+
tuple[Type, ...],
60+
tuple[Type, ...],
61+
tuple[Type, ...],
62+
tuple[Type, ...],
63+
]
64+
| None
65+
):
6366
split_result = fully_split_with_mapped_and_template(
6467
mapped,
6568
mapped_prefix_len,
@@ -101,18 +104,21 @@ def fully_split_with_mapped_and_template(
101104
template: tuple[Type, ...],
102105
template_prefix_len: int,
103106
template_suffix_len: int,
104-
) -> tuple[
105-
tuple[Type, ...],
106-
tuple[Type, ...],
107-
tuple[Type, ...],
108-
tuple[Type, ...],
109-
tuple[Type, ...],
110-
tuple[Type, ...],
111-
tuple[Type, ...],
112-
tuple[Type, ...],
113-
tuple[Type, ...],
114-
tuple[Type, ...],
115-
] | None:
107+
) -> (
108+
tuple[
109+
tuple[Type, ...],
110+
tuple[Type, ...],
111+
tuple[Type, ...],
112+
tuple[Type, ...],
113+
tuple[Type, ...],
114+
tuple[Type, ...],
115+
tuple[Type, ...],
116+
tuple[Type, ...],
117+
tuple[Type, ...],
118+
tuple[Type, ...],
119+
]
120+
| None
121+
):
116122
if mapped_prefix_len is not None:
117123
assert mapped_suffix_len is not None
118124
mapped_prefix, mapped_middle, mapped_suffix = split_with_prefix_and_suffix(

0 commit comments

Comments
 (0)