Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable 80 col hard wrapping in mypy output #16488

Merged
merged 11 commits into from
Aug 19, 2022
5 changes: 5 additions & 0 deletions src/python/pants/backend/python/typecheck/mypy/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ async def mypy_typecheck_partition(
env = {
"PEX_EXTRA_SYS_PATH": ":".join(all_used_source_roots),
"MYPYPATH": ":".join(all_used_source_roots),
# Similarly, force a fixed terminal width. This is effectively infinite, disabling mypy's
# builtin truncation and line wrapping. Terminals do an acceptable job of soft-wrapping
# diagnostic text and source code is typically already hard-wrapped to a limited width.
# (Unique random number to make it easier to search for the source of this setting.)
"MYPY_FORCE_TERMINAL_WIDTH": "642092230765939",
}

process = await Get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import annotations

import re
from textwrap import dedent

import pytest
Expand Down Expand Up @@ -872,3 +873,31 @@ def test_determine_python_files() -> None:
assert determine_python_files(["f.py", "f.pyi"]) == ("f.pyi",)
assert determine_python_files(["f.pyi", "f.py"]) == ("f.pyi",)
assert determine_python_files(["f.json"]) == ()


def test_colors_and_formatting(rule_runner: RuleRunner) -> None:
rule_runner.write_files(
{
f"{PACKAGE}/f.py": dedent(
"""\
class incredibly_long_type_name_to_force_wrapping_if_mypy_wrapped_error_messages_12345678901234567890123456789012345678901234567890:
pass

x = incredibly_long_type_name_to_force_wrapping_if_mypy_wrapped_error_messages_12345678901234567890123456789012345678901234567890()
x.incredibly_long_attribute_name_to_force_wrapping_if_mypy_wrapped_error_messages_12345678901234567890123456789012345678901234567890
"""
),
f"{PACKAGE}/BUILD": "python_sources()",
}
)
tgt = rule_runner.get_target(Address(PACKAGE, relative_file_path="f.py"))

result = run_mypy(rule_runner, [tgt], extra_args=["--colors=true", "--mypy-args=--pretty"])

assert len(result) == 1
assert result[0].exit_code == 1
# all one line
assert re.search(
"error:.*incredibly_long_type_name.*incredibly_long_attribute_name", result[0].stdout
)
assert result[0].report == EMPTY_DIGEST