Skip to content

Stubtest: Link directly to line #14437

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

Merged
merged 4 commits into from
Feb 18, 2023
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
4 changes: 2 additions & 2 deletions docs/source/stubtest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test Python's official collection of library stubs,
`typeshed <https://github.com/python/typeshed>`_.

.. warning::

stubtest will import and execute Python code from the packages it checks.

Example
Expand All @@ -69,7 +69,7 @@ Here's a quick example of what stubtest can do:
error: library.foo is inconsistent, runtime argument "x" has a default value but stub argument does not
Stub: at line 3
def (x: builtins.int)
Runtime: at line 3 in file ~/library.py
Runtime: in file ~/library.py:3
def (x=None)

error: library.x variable differs from runtime type Literal['hello, stubtest']
Expand Down
8 changes: 4 additions & 4 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ def get_description(self, concise: bool = False) -> str:
stub_file = stub_node.path or None

stub_loc_str = ""
if stub_line:
stub_loc_str += f" at line {stub_line}"
if stub_file:
stub_loc_str += f" in file {Path(stub_file)}"
if stub_line:
stub_loc_str += f"{':' if stub_file else ' at line '}{stub_line}"

runtime_line = None
runtime_file = None
Expand All @@ -147,10 +147,10 @@ def get_description(self, concise: bool = False) -> str:
pass

runtime_loc_str = ""
if runtime_line:
runtime_loc_str += f" at line {runtime_line}"
if runtime_file:
runtime_loc_str += f" in file {Path(runtime_file)}"
if runtime_line:
runtime_loc_str += f"{':' if runtime_file else ' at line '}{runtime_line}"

output = [
_style("error: ", color="red", bold=True),
Expand Down
4 changes: 1 addition & 3 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ def parse_test_case(case: DataDrivenTestCase) -> None:
elif item.id == "triggered" and item.arg is None:
triggered = item.data
else:
raise ValueError(
f"Invalid section header {item.id} in {case.file} at line {item.line}"
)
raise ValueError(f"Invalid section header {item.id} in {case.file}:{item.line}")

if out_section_missing:
raise ValueError(f"{case.file}, line {first_item.line}: Required output section not found")
Expand Down
6 changes: 3 additions & 3 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,9 +1518,9 @@ def test_output(self) -> None:
expected = (
f'error: {TEST_MODULE_NAME}.bad is inconsistent, stub argument "number" differs '
'from runtime argument "num"\n'
f"Stub: at line 1 in file {TEST_MODULE_NAME}.pyi\n"
f"Stub: in file {TEST_MODULE_NAME}.pyi:1\n"
"def (number: builtins.int, text: builtins.str)\n"
f"Runtime: at line 1 in file {TEST_MODULE_NAME}.py\ndef (num, text)\n\n"
f"Runtime: in file {TEST_MODULE_NAME}.py:1\ndef (num, text)\n\n"
"Found 1 error (checked 1 module)\n"
)
assert remove_color_code(output) == expected
Expand Down Expand Up @@ -1678,7 +1678,7 @@ def test_config_file(self) -> None:
output = run_stubtest(stub=stub, runtime=runtime, options=[])
assert remove_color_code(output) == (
f"error: {TEST_MODULE_NAME}.temp variable differs from runtime type Literal[5]\n"
f"Stub: at line 2 in file {TEST_MODULE_NAME}.pyi\n_decimal.Decimal\nRuntime:\n5\n\n"
f"Stub: in file {TEST_MODULE_NAME}.pyi:2\n_decimal.Decimal\nRuntime:\n5\n\n"
"Found 1 error (checked 1 module)\n"
)
output = run_stubtest(stub=stub, runtime=runtime, options=[], config_file=config_file)
Expand Down