From 52fa13c9a54da2003b8cdb2507408214d2017c33 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 12 Jan 2023 08:40:21 -0500 Subject: [PATCH 1/3] Link directly to line This format allows editors that support linking to specific lines in files to go directly to the right line. --- mypy/stubtest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index bfd8e2b9c81a..a9087f352984 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -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":{stub_line}" runtime_line = None runtime_file = None @@ -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":{runtime_line}" output = [ _style("error: ", color="red", bold=True), From 1d63648cb3e12a2be5cc6dcf54dee28abdcd23a0 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 23 Jan 2023 11:31:04 -0500 Subject: [PATCH 2/3] Update all " at line " --- docs/source/stubtest.rst | 4 ++-- mypy/stubtest.py | 12 ++++++------ mypy/test/data.py | 4 +--- mypy/test/teststubtest.py | 6 +++--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/source/stubtest.rst b/docs/source/stubtest.rst index a8279eb6c239..f3c036f56c06 100644 --- a/docs/source/stubtest.rst +++ b/docs/source/stubtest.rst @@ -42,7 +42,7 @@ test Python's official collection of library stubs, `typeshed `_. .. warning:: - + stubtest will import and execute Python code from the packages it checks. Example @@ -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'] diff --git a/mypy/stubtest.py b/mypy/stubtest.py index a9087f352984..f03983f95eee 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -132,7 +132,7 @@ def get_description(self, concise: bool = False) -> str: if stub_file: stub_loc_str += f" in file {Path(stub_file)}" if stub_line: - stub_loc_str += f":{stub_line}" + stub_loc_str += f"{':' if stub_file else ' at line '}{stub_line}" runtime_line = None runtime_file = None @@ -563,7 +563,7 @@ def _verify_arg_name( return def strip_prefix(s: str, prefix: str) -> str: - return s[len(prefix) :] if s.startswith(prefix) else s + return s[len(prefix):] if s.startswith(prefix) else s if strip_prefix(stub_arg.variable.name, "__") == runtime_arg.name: return @@ -853,7 +853,7 @@ def _verify_signature( # runtime has all of the stub's parameters, b) below, we don't enforce that the stub takes # *args, since runtime logic may prevent arbitrary arguments from actually being accepted. if runtime.varpos is None: - for stub_arg in stub.pos[len(runtime.pos) :]: + for stub_arg in stub.pos[len(runtime.pos):]: # If the variable is in runtime.kwonly, it's just mislabelled as not a # keyword-only argument if stub_arg.variable.name not in runtime.kwonly: @@ -863,7 +863,7 @@ def _verify_signature( if stub.varpos is not None: yield f'runtime does not have *args argument "{stub.varpos.variable.name}"' elif len(stub.pos) < len(runtime.pos): - for runtime_arg in runtime.pos[len(stub.pos) :]: + for runtime_arg in runtime.pos[len(stub.pos):]: if runtime_arg.name not in stub.kwonly: yield f'stub does not have argument "{runtime_arg.name}"' else: @@ -892,7 +892,7 @@ def _verify_signature( for arg in sorted(set(stub.kwonly) - set(runtime.kwonly)): if arg in {runtime_arg.name for runtime_arg in runtime.pos}: # Don't report this if we've reported it before - if arg not in {runtime_arg.name for runtime_arg in runtime.pos[len(stub.pos) :]}: + if arg not in {runtime_arg.name for runtime_arg in runtime.pos[len(stub.pos):]}: yield f'runtime argument "{arg}" is not keyword-only' else: yield f'runtime does not have argument "{arg}"' @@ -901,7 +901,7 @@ def _verify_signature( # Don't report this if we've reported it before if not ( runtime.varpos is None - and arg in {stub_arg.variable.name for stub_arg in stub.pos[len(runtime.pos) :]} + and arg in {stub_arg.variable.name for stub_arg in stub.pos[len(runtime.pos):]} ): yield f'stub argument "{arg}" is not keyword-only' else: diff --git a/mypy/test/data.py b/mypy/test/data.py index f4cb39818b4e..66d1b329e446 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -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") diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py index 5e59d8efec63..952c00b8afa1 100644 --- a/mypy/test/teststubtest.py +++ b/mypy/test/teststubtest.py @@ -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 @@ -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) From 5f1b086f26d450ee1b09dd26a936ba6527f2f9e2 Mon Sep 17 00:00:00 2001 From: Avasam Date: Mon, 23 Jan 2023 11:33:26 -0500 Subject: [PATCH 3/3] . --- mypy/stubtest.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index f03983f95eee..45e48ce05ff3 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -150,7 +150,7 @@ def get_description(self, concise: bool = False) -> str: if runtime_file: runtime_loc_str += f" in file {Path(runtime_file)}" if runtime_line: - runtime_loc_str += f":{runtime_line}" + runtime_loc_str += f"{':' if runtime_file else ' at line '}{runtime_line}" output = [ _style("error: ", color="red", bold=True), @@ -563,7 +563,7 @@ def _verify_arg_name( return def strip_prefix(s: str, prefix: str) -> str: - return s[len(prefix):] if s.startswith(prefix) else s + return s[len(prefix) :] if s.startswith(prefix) else s if strip_prefix(stub_arg.variable.name, "__") == runtime_arg.name: return @@ -853,7 +853,7 @@ def _verify_signature( # runtime has all of the stub's parameters, b) below, we don't enforce that the stub takes # *args, since runtime logic may prevent arbitrary arguments from actually being accepted. if runtime.varpos is None: - for stub_arg in stub.pos[len(runtime.pos):]: + for stub_arg in stub.pos[len(runtime.pos) :]: # If the variable is in runtime.kwonly, it's just mislabelled as not a # keyword-only argument if stub_arg.variable.name not in runtime.kwonly: @@ -863,7 +863,7 @@ def _verify_signature( if stub.varpos is not None: yield f'runtime does not have *args argument "{stub.varpos.variable.name}"' elif len(stub.pos) < len(runtime.pos): - for runtime_arg in runtime.pos[len(stub.pos):]: + for runtime_arg in runtime.pos[len(stub.pos) :]: if runtime_arg.name not in stub.kwonly: yield f'stub does not have argument "{runtime_arg.name}"' else: @@ -892,7 +892,7 @@ def _verify_signature( for arg in sorted(set(stub.kwonly) - set(runtime.kwonly)): if arg in {runtime_arg.name for runtime_arg in runtime.pos}: # Don't report this if we've reported it before - if arg not in {runtime_arg.name for runtime_arg in runtime.pos[len(stub.pos):]}: + if arg not in {runtime_arg.name for runtime_arg in runtime.pos[len(stub.pos) :]}: yield f'runtime argument "{arg}" is not keyword-only' else: yield f'runtime does not have argument "{arg}"' @@ -901,7 +901,7 @@ def _verify_signature( # Don't report this if we've reported it before if not ( runtime.varpos is None - and arg in {stub_arg.variable.name for stub_arg in stub.pos[len(runtime.pos):]} + and arg in {stub_arg.variable.name for stub_arg in stub.pos[len(runtime.pos) :]} ): yield f'stub argument "{arg}" is not keyword-only' else: