diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1466c8e0fda4..b7b8a5cd3335 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - repo: https://github.com/psf/black-pre-commit-mirror - rev: 25.9.0 + rev: 26.1.0 hooks: - id: black exclude: '^(test-data/)' diff --git a/misc/sync-typeshed.py b/misc/sync-typeshed.py index 22023234710e..06da147e4ff8 100644 --- a/misc/sync-typeshed.py +++ b/misc/sync-typeshed.py @@ -184,14 +184,12 @@ def main() -> None: assert commit # Create a commit - message = textwrap.dedent( - f"""\ + message = textwrap.dedent(f"""\ Sync typeshed Source commit: https://github.com/python/typeshed/commit/{commit} - """ - ) + """) subprocess.run(["git", "add", "--all", os.path.join("mypy", "typeshed")], check=True) subprocess.run(["git", "commit", "-m", message], check=True) print("Created typeshed sync commit.") diff --git a/mypy/build.py b/mypy/build.py index f7e13cfb5791..bfcc897cf2fa 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -1432,12 +1432,10 @@ def exclude_from_backups(target_dir: str) -> None: cachedir_tag = os.path.join(target_dir, "CACHEDIR.TAG") try: with open(cachedir_tag, "x") as f: - f.write( - """Signature: 8a477f597d28d172789f06886806bc55 + f.write("""Signature: 8a477f597d28d172789f06886806bc55 # This file is a cache directory tag automatically created by mypy. # For information about cache directory tags see https://bford.info/cachedir/ -""" - ) +""") except FileExistsError: pass diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 2f6743bc7ff3..149575ab37aa 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -2116,7 +2116,7 @@ def infer_function_type_arguments( if 2 in arg_pass_nums: # Second pass of type inference. - (callee_type, inferred_args) = self.infer_function_type_arguments_pass2( + callee_type, inferred_args = self.infer_function_type_arguments_pass2( callee_type, args, arg_kinds, @@ -6462,7 +6462,7 @@ def try_parse_as_type_expression(self, maybe_type_expr: Expression) -> Type | No # Collect symbols targeted by NameExprs and MemberExprs, # to be looked up by TypeAnalyser when binding the # UnboundTypes corresponding to those expressions. - (name_exprs, member_exprs) = all_name_and_member_expressions(maybe_type_expr) + name_exprs, member_exprs = all_name_and_member_expressions(maybe_type_expr) sym_for_name = {e.name: SymbolTableNode(UNBOUND_IMPORTED, e.node) for e in name_exprs} | { e_name: SymbolTableNode(UNBOUND_IMPORTED, e.node) for e in member_exprs diff --git a/mypy/checkpattern.py b/mypy/checkpattern.py index 839bec078a2f..c2deb16936bd 100644 --- a/mypy/checkpattern.py +++ b/mypy/checkpattern.py @@ -312,7 +312,7 @@ def visit_sequence_pattern(self, o: SequencePattern) -> PatternType: narrowed_inner_types = [] inner_rest_types = [] for inner_type, new_inner_type in zip(inner_types, new_inner_types): - (narrowed_inner_type, inner_rest_type) = ( + narrowed_inner_type, inner_rest_type = ( self.chk.conditional_types_with_intersection( inner_type, [get_type_range(new_inner_type)], o, default=inner_type ) diff --git a/mypy/fastparse.py b/mypy/fastparse.py index c349b3cb1385..a8ed5eb038f5 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -634,7 +634,7 @@ def fix_function_overloads(self, stmts: list[Statement]) -> list[Statement]: # Check IfStmt block to determine if function overloads can be merged if_overload_name = self._check_ifstmt_for_overloads(stmt, current_overload_name) if if_overload_name is not None: - (if_block_with_overload, if_unknown_truth_value) = ( + if_block_with_overload, if_unknown_truth_value = ( self._get_executable_if_block_with_overloads(stmt) ) diff --git a/mypy/messages.py b/mypy/messages.py index 5863b8719b95..0a255582d139 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -1295,17 +1295,13 @@ def argument_incompatible_with_supertype( ) def comparison_method_example_msg(self, class_name: str) -> str: - return dedent( - """\ + return dedent("""\ It is recommended for "__eq__" to work with arbitrary objects, for example: def __eq__(self, other: object) -> bool: if not isinstance(other, {class_name}): return NotImplemented return - """.format( - class_name=class_name - ) - ) + """.format(class_name=class_name)) def return_type_incompatible_with_supertype( self, @@ -1802,7 +1798,7 @@ def redundant_cast(self, typ: Type, context: Context) -> None: ) def assert_type_fail(self, source_type: Type, target_type: Type, context: Context) -> None: - (source, target) = format_type_distinctly(source_type, target_type, options=self.options) + source, target = format_type_distinctly(source_type, target_type, options=self.options) self.fail(f"Expression is of type {source}, not {target}", context, code=codes.ASSERT_TYPE) def unimported_type_becomes_any(self, prefix: str, typ: Type, ctx: Context) -> None: diff --git a/mypy/report.py b/mypy/report.py index ce6a59a00209..885d077d259e 100644 --- a/mypy/report.py +++ b/mypy/report.py @@ -285,7 +285,7 @@ def _report_any_exprs(self) -> None: column_names = ["Name", "Anys", "Exprs", "Coverage"] rows: list[list[str]] = [] for filename in sorted(self.counts): - (num_any, num_total) = self.counts[filename] + num_any, num_total = self.counts[filename] coverage = (float(num_total - num_any) / float(num_total)) * 100 coverage_str = f"{coverage:.2f}%" rows.append([filename, str(num_any), str(num_total), coverage_str]) diff --git a/mypy/semanal_typeddict.py b/mypy/semanal_typeddict.py index 8bf073d30f71..b912ea177187 100644 --- a/mypy/semanal_typeddict.py +++ b/mypy/semanal_typeddict.py @@ -162,7 +162,7 @@ def analyze_typeddict_classdef(self, defn: ClassDef) -> tuple[bool, TypeInfo | N self.add_keys_and_types_from_base( base, field_types, required_keys, readonly_keys, defn ) - (new_field_types, new_statements, new_required_keys, new_readonly_keys) = ( + new_field_types, new_statements, new_required_keys, new_readonly_keys = ( self.analyze_typeddict_classdef_fields(defn, oldfields=field_types) ) if new_field_types is None: diff --git a/mypy/test/meta/test_parse_data.py b/mypy/test/meta/test_parse_data.py index 3261fcd51371..07343414293c 100644 --- a/mypy/test/meta/test_parse_data.py +++ b/mypy/test/meta/test_parse_data.py @@ -14,28 +14,24 @@ def _run_pytest(data_suite: str) -> PytestResult: class ParseTestDataSuite(Suite): def test_parse_invalid_case(self) -> None: # Act - result = _run_pytest( - """ + result = _run_pytest(""" [case abc] s: str [case foo-XFAIL] s: str - """ - ) + """) # Assert assert "Invalid testcase id 'foo-XFAIL'" in result.stdout def test_parse_invalid_section(self) -> None: # Act - result = _run_pytest( - """ + result = _run_pytest(""" [case abc] s: str [unknownsection] abc - """ - ) + """) # Assert expected_lineno = result.input.splitlines().index("[unknownsection]") + 1 @@ -46,14 +42,12 @@ def test_parse_invalid_section(self) -> None: def test_bad_ge_version_check(self) -> None: # Act - actual = _run_pytest( - """ + actual = _run_pytest(""" [case abc] s: str [out version>=3.10] abc - """ - ) + """) # Assert assert ( @@ -62,14 +56,12 @@ def test_bad_ge_version_check(self) -> None: def test_bad_eq_version_check(self) -> None: # Act - actual = _run_pytest( - """ + actual = _run_pytest(""" [case abc] s: str [out version==3.7] abc - """ - ) + """) # Assert assert ( diff --git a/mypy/test/meta/test_update_data.py b/mypy/test/meta/test_update_data.py index 820fd359893e..8e1c090fc68d 100644 --- a/mypy/test/meta/test_update_data.py +++ b/mypy/test/meta/test_update_data.py @@ -20,8 +20,7 @@ class UpdateDataSuite(Suite): def test_update_data(self) -> None: # Note: We test multiple testcases rather than 'test case per test case' # so we could also exercise rewriting multiple testcases at once. - result = _run_pytest_update_data( - """ + result = _run_pytest_update_data(""" [case testCorrect] s: str = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "str") @@ -74,12 +73,10 @@ def test_update_data(self) -> None: [file b.py] s2: str = 43 # E: baz [builtins fixtures/list.pyi] - """ - ) + """) # Assert - expected = dedent_docstring( - """ + expected = dedent_docstring(""" [case testCorrect] s: str = 42 # E: Incompatible types in assignment (expression has type "int", variable has type "str") @@ -130,6 +127,5 @@ def test_update_data(self) -> None: [file b.py] s2: str = 43 # E: Incompatible types in assignment (expression has type "int", variable has type "str") [builtins fixtures/list.pyi] - """ - ) + """) assert result.input_updated == expected diff --git a/mypy/test/testreports.py b/mypy/test/testreports.py index a971f297ec92..63a9e6eac8bd 100644 --- a/mypy/test/testreports.py +++ b/mypy/test/testreports.py @@ -42,8 +42,7 @@ def test_as_xml(self) -> None: cobertura_package.packages["raz"] = child_package - expected_output = textwrap.dedent( - """\ + expected_output = textwrap.dedent("""\ @@ -54,8 +53,7 @@ def test_as_xml(self) -> None: - """ - ).encode("ascii") + """).encode("ascii") assert_equal( expected_output, etree.tostring(cobertura_package.as_xml(), pretty_print=True) ) diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py index 18f68356c855..45cc46c40108 100644 --- a/mypy/test/teststubtest.py +++ b/mypy/test/teststubtest.py @@ -2825,24 +2825,16 @@ def test_allowlist(self) -> None: f.write("unused.*\n") output = run_stubtest( - stub=textwrap.dedent( - """ + stub=textwrap.dedent(""" def good() -> None: ... def bad(number: int) -> None: ... def also_bad(number: int) -> None: ... - """.lstrip( - "\n" - ) - ), - runtime=textwrap.dedent( - """ + """.lstrip("\n")), + runtime=textwrap.dedent(""" def good(): pass def bad(asdf): pass def also_bad(asdf): pass - """.lstrip( - "\n" - ) - ), + """.lstrip("\n")), options=["--allowlist", allowlist.name, "--generate-allowlist"], ) assert output == ( diff --git a/mypyc/ir/ops.py b/mypyc/ir/ops.py index 36105e3538d8..fa6b6af7bcf3 100644 --- a/mypyc/ir/ops.py +++ b/mypyc/ir/ops.py @@ -1547,7 +1547,7 @@ def sources(self) -> list[Value]: return [self.lhs, self.rhs] def set_sources(self, new: list[Value]) -> None: - (self.lhs, self.rhs) = new + self.lhs, self.rhs = new def accept(self, visitor: OpVisitor[T]) -> T: return visitor.visit_float_op(self) @@ -1605,7 +1605,7 @@ def sources(self) -> list[Value]: return [self.lhs, self.rhs] def set_sources(self, new: list[Value]) -> None: - (self.lhs, self.rhs) = new + self.lhs, self.rhs = new def accept(self, visitor: OpVisitor[T]) -> T: return visitor.visit_float_comparison_op(self) diff --git a/mypyc/test/test_emit.py b/mypyc/test/test_emit.py index 1baed3964299..4f6713644776 100644 --- a/mypyc/test/test_emit.py +++ b/mypyc/test/test_emit.py @@ -42,12 +42,9 @@ def test_reg(self) -> None: def test_object_annotation(self) -> None: assert self.emitter.object_annotation("hello, world", "line;") == " /* 'hello, world' */" - assert ( - self.emitter.object_annotation(list(range(30)), "line;") - == """\ + assert self.emitter.object_annotation(list(range(30)), "line;") == """\ /* [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] */""" - ) def test_emit_line(self) -> None: emitter = self.emitter @@ -60,12 +57,9 @@ def test_emit_line(self) -> None: emitter.emit_line("CPyStatics[0];", ann="hello, world") emitter.emit_line("CPyStatics[1];", ann=list(range(30))) assert emitter.fragments[0] == "CPyStatics[0]; /* 'hello, world' */\n" - assert ( - emitter.fragments[1] - == """\ + assert emitter.fragments[1] == """\ CPyStatics[1]; /* [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] */\n""" - ) def test_emit_undefined_value_for_simple_type(self) -> None: emitter = self.emitter