From 1c896b34994dbe68588900ce4a4faf2a5384028d Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 6 Aug 2022 02:24:08 -0700 Subject: [PATCH 1/2] stubtest: show path to stub file --- mypy/stubtest.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index b51d107448d9..9b2736d04a85 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -90,6 +90,7 @@ def __init__( :param runtime_desc: Specialised description for the runtime object, should you wish """ + self.object_path = object_path self.object_desc = ".".join(object_path) self.message = message self.stub_object = stub_object @@ -116,10 +117,12 @@ def get_description(self, concise: bool = False) -> str: return _style(self.object_desc, bold=True) + " " + self.message stub_line = None - stub_file: None = None + stub_file = None if not isinstance(self.stub_object, Missing): stub_line = self.stub_object.line - # TODO: Find a way of getting the stub file + stub_node = get_stub(self.object_path[0]) + if stub_node is not None: + stub_file = stub_node.path or None stub_loc_str = "" if stub_line: From 0aeac72deb1608279a447919117c634d78c77b2e Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Sat, 6 Aug 2022 04:02:30 -0700 Subject: [PATCH 2/2] fix tests --- mypy/test/teststubtest.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py index 2adbfaac2ae7..1bdc47537296 100644 --- a/mypy/test/teststubtest.py +++ b/mypy/test/teststubtest.py @@ -121,7 +121,11 @@ def run_stubtest( with contextlib.redirect_stdout(output): test_stubs(parse_options([TEST_MODULE_NAME] + options), use_builtins_fixtures=True) # remove cwd as it's not available from outside - return output.getvalue().replace(tmp_dir + os.sep, "") + return ( + output.getvalue() + .replace(os.path.realpath(tmp_dir) + os.sep, "") + .replace(tmp_dir + os.sep, "") + ) class Case: @@ -1274,7 +1278,8 @@ def test_output(self) -> None: expected = ( f'error: {TEST_MODULE_NAME}.bad is inconsistent, stub argument "number" differs ' 'from runtime argument "num"\n' - "Stub: at line 1\ndef (number: builtins.int, text: builtins.str)\n" + f"Stub: at line 1 in file {TEST_MODULE_NAME}.pyi\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" "Found 1 error (checked 1 module)\n" ) @@ -1432,7 +1437,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" - "Stub: at line 2\n_decimal.Decimal\nRuntime:\n5\n\n" + f"Stub: at line 2 in file {TEST_MODULE_NAME}.pyi\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)