Skip to content

Commit d0d5876

Browse files
authored
Fix various lint (#16726)
1 parent 4aba5ca commit d0d5876

41 files changed

Lines changed: 102 additions & 93 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
hooks:
1111
- id: black
1212
- repo: https://github.com/astral-sh/ruff-pre-commit
13-
rev: v0.1.0 # must match test-requirements.txt
13+
rev: v0.1.4 # must match test-requirements.txt
1414
hooks:
1515
- id: ruff
1616
args: [--exit-non-zero-on-fix]

‎mypy/binder.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def assign_type(
291291
self.type_assignments[expr].append((type, declared_type))
292292
return
293293
if not isinstance(expr, (IndexExpr, MemberExpr, NameExpr)):
294-
return None
294+
return
295295
if not literal(expr):
296296
return
297297
self.invalidate_dependencies(expr)

‎mypy/build.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,7 @@ def __init__(
682682
# for efficient lookup
683683
self.shadow_map: dict[str, str] = {}
684684
if self.options.shadow_file is not None:
685-
self.shadow_map = {
686-
source_file: shadow_file for (source_file, shadow_file) in self.options.shadow_file
687-
}
685+
self.shadow_map = dict(self.options.shadow_file)
688686
# a mapping from each file being typechecked to its possible shadow file
689687
self.shadow_equivalence_map: dict[str, str | None] = {}
690688
self.plugin = plugin
@@ -1120,7 +1118,7 @@ def read_deps_cache(manager: BuildManager, graph: Graph) -> dict[str, FgDepMeta]
11201118
module_deps_metas = deps_meta["deps_meta"]
11211119
assert isinstance(module_deps_metas, dict)
11221120
if not manager.options.skip_cache_mtime_checks:
1123-
for id, meta in module_deps_metas.items():
1121+
for meta in module_deps_metas.values():
11241122
try:
11251123
matched = manager.getmtime(meta["path"]) == meta["mtime"]
11261124
except FileNotFoundError:
@@ -2093,7 +2091,7 @@ def load_tree(self, temporary: bool = False) -> None:
20932091
self.meta.data_json, self.manager, "Load tree ", "Could not load tree: "
20942092
)
20952093
if data is None:
2096-
return None
2094+
return
20972095

20982096
t0 = time.time()
20992097
# TODO: Assert data file wasn't changed.
@@ -3383,7 +3381,7 @@ def order_ascc(graph: Graph, ascc: AbstractSet[str], pri_max: int = PRI_ALL) ->
33833381
strongly_connected_components() below for a reference.
33843382
"""
33853383
if len(ascc) == 1:
3386-
return [s for s in ascc]
3384+
return list(ascc)
33873385
pri_spread = set()
33883386
for id in ascc:
33893387
state = graph[id]

‎mypy/checker.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
632632
if not defn.items:
633633
# In this case we have already complained about none of these being
634634
# valid overloads.
635-
return None
635+
return
636636
if len(defn.items) == 1:
637637
self.fail(message_registry.MULTIPLE_OVERLOADS_REQUIRED, defn)
638638

@@ -676,7 +676,6 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
676676
self.msg.no_overridable_method(defn.name, defn)
677677
self.check_explicit_override_decorator(defn, found_method_base_classes, defn.impl)
678678
self.check_inplace_operator_method(defn)
679-
return None
680679

681680
def extract_callable_type(self, inner_type: Type | None, ctx: Context) -> CallableType | None:
682681
"""Get type as seen by an overload item caller."""
@@ -1838,7 +1837,7 @@ def check_match_args(self, var: Var, typ: Type, context: Context) -> None:
18381837
return
18391838
typ = get_proper_type(typ)
18401839
if not isinstance(typ, TupleType) or not all(
1841-
[is_string_literal(item) for item in typ.items]
1840+
is_string_literal(item) for item in typ.items
18421841
):
18431842
self.msg.note(
18441843
"__match_args__ must be a tuple containing string literals for checking "
@@ -5045,7 +5044,7 @@ def visit_break_stmt(self, s: BreakStmt) -> None:
50455044

50465045
def visit_continue_stmt(self, s: ContinueStmt) -> None:
50475046
self.binder.handle_continue()
5048-
return None
5047+
return
50495048

50505049
def visit_match_stmt(self, s: MatchStmt) -> None:
50515050
with self.binder.frame_context(can_skip=False, fall_through=0):

‎mypy/checkexpr.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def check_typeddict_call(
739739
context: Context,
740740
orig_callee: Type | None,
741741
) -> Type:
742-
if args and all([ak in (ARG_NAMED, ARG_STAR2) for ak in arg_kinds]):
742+
if args and all(ak in (ARG_NAMED, ARG_STAR2) for ak in arg_kinds):
743743
# ex: Point(x=42, y=1337, **extras)
744744
# This is a bit ugly, but this is a price for supporting all possible syntax
745745
# variants for TypedDict constructors.
@@ -4017,9 +4017,7 @@ def check_op(
40174017
left_variants = [base_type]
40184018
base_type = get_proper_type(base_type)
40194019
if isinstance(base_type, UnionType):
4020-
left_variants = [
4021-
item for item in flatten_nested_unions(base_type.relevant_items())
4022-
]
4020+
left_variants = list(flatten_nested_unions(base_type.relevant_items()))
40234021
right_type = self.accept(arg)
40244022

40254023
# Step 1: We first try leaving the right arguments alone and destructure

‎mypy/checkpattern.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def visit_or_pattern(self, o: OrPattern) -> PatternType:
187187
capture_types[node].append((expr, typ))
188188

189189
captures: dict[Expression, Type] = {}
190-
for var, capture_list in capture_types.items():
190+
for capture_list in capture_types.values():
191191
typ = UninhabitedType()
192192
for _, other in capture_list:
193193
typ = join_types(typ, other)

‎mypy/checkstrformat.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def check_specs_in_format_call(
372372
):
373373
# TODO: add support for some custom specs like datetime?
374374
self.msg.fail(
375-
"Unrecognized format" ' specification "{}"'.format(spec.format_spec[1:]),
375+
f'Unrecognized format specification "{spec.format_spec[1:]}"',
376376
call,
377377
code=codes.STRING_FORMATTING,
378378
)
@@ -482,7 +482,7 @@ def find_replacements_in_call(self, call: CallExpr, keys: list[str]) -> list[Exp
482482
expr = self.get_expr_by_name(key, call)
483483
if not expr:
484484
self.msg.fail(
485-
"Cannot find replacement for named" ' format specifier "{}"'.format(key),
485+
f'Cannot find replacement for named format specifier "{key}"',
486486
call,
487487
code=codes.STRING_FORMATTING,
488488
)

‎mypy/dmypy_server.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ def fix_module_deps(graph: mypy.build.Graph) -> None:
10551055
This can make some suppressed dependencies non-suppressed, and vice versa (if modules
10561056
have been added to or removed from the build).
10571057
"""
1058-
for module, state in graph.items():
1058+
for state in graph.values():
10591059
new_suppressed = []
10601060
new_dependencies = []
10611061
for dep in state.dependencies + state.suppressed:

‎mypy/dmypy_util.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def send(connection: IPCBase, data: Any) -> None:
4343
class WriteToConn:
4444
"""Helper class to write to a connection instead of standard output."""
4545

46-
def __init__(self, server: IPCBase, output_key: str = "stdout"):
46+
def __init__(self, server: IPCBase, output_key: str = "stdout") -> None:
4747
self.server = server
4848
self.output_key = output_key
4949

‎mypy/errors.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def __init__(
170170
*,
171171
filter_errors: bool | Callable[[str, ErrorInfo], bool] = False,
172172
save_filtered_errors: bool = False,
173-
):
173+
) -> None:
174174
self.errors = errors
175175
self._has_new_errors = False
176176
self._filter = filter_errors

0 commit comments

Comments
 (0)