Skip to content

Commit

Permalink
fix[ux]: improve initializer hint for unimported modules (#4145)
Browse files Browse the repository at this point in the history
improve initializer hint in the case that the needed module is not
already imported
  • Loading branch information
charles-cooper authored Jun 13, 2024
1 parent 153262b commit e9e9d78
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tests/functional/syntax/modules/test_initializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ def foo():
assert e.value._hint == "add `lib3 := lib3` to its initializer list"


def test_hint_for_missing_initializer_when_no_import(make_input_bundle):
def test_hint_for_missing_initializer_when_no_import(make_input_bundle, chdir_tmp_path):
lib1 = """
counter: uint256
"""
Expand All @@ -1297,7 +1297,8 @@ def foo():
with pytest.raises(InitializerException) as e:
compile_code(main, input_bundle=input_bundle)
assert e.value._message == "`lib2` uses `lib1`, but it is not initialized with `lib1`"
assert e.value._hint == "try importing lib1 first"
hint = "try importing `lib1` first (located at `lib1.vy`)"
assert e.value._hint == hint


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion vyper/semantics/analysis/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ def visit_InitializesDecl(self, node):
break

if rhs is None:
hint = f"try importing {item.alias} first"
hint = f"try importing `{item.alias}` first "
hint += f"(located at `{item.module_t._module.path}`)"
elif not isinstance(annotation, vy_ast.Subscript):
# it's `initializes: foo` instead of `initializes: foo[...]`
hint = f"did you mean {module_ref.id}[{lhs} := {rhs}]?"
Expand Down

0 comments on commit e9e9d78

Please sign in to comment.