Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/)'
Expand Down
6 changes: 2 additions & 4 deletions misc/sync-typeshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
6 changes: 2 additions & 4 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mypy/checkpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand Down
10 changes: 3 additions & 7 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <logic to compare two {class_name} instances>
""".format(
class_name=class_name
)
)
""".format(class_name=class_name))

def return_type_incompatible_with_supertype(
self,
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion mypy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion mypy/semanal_typeddict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 8 additions & 16 deletions mypy/test/meta/test_parse_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand All @@ -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 (
Expand Down
12 changes: 4 additions & 8 deletions mypy/test/meta/test_update_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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
6 changes: 2 additions & 4 deletions mypy/test/testreports.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def test_as_xml(self) -> None:

cobertura_package.packages["raz"] = child_package

expected_output = textwrap.dedent(
"""\
expected_output = textwrap.dedent("""\
<package complexity="1.0" name="foobar" branch-rate="0" line-rate="0.5000">
<classes/>
<packages>
Expand All @@ -54,8 +53,7 @@ def test_as_xml(self) -> None:
</package>
</packages>
</package>
"""
).encode("ascii")
""").encode("ascii")
assert_equal(
expected_output, etree.tostring(cobertura_package.as_xml(), pretty_print=True)
)
16 changes: 4 additions & 12 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == (
Expand Down
4 changes: 2 additions & 2 deletions mypyc/ir/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 2 additions & 8 deletions mypyc/test/test_emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down