diff --git a/tests/functional/syntax/modules/test_exports.py b/tests/functional/syntax/modules/test_exports.py index 7b00d29c98..1595693c25 100644 --- a/tests/functional/syntax/modules/test_exports.py +++ b/tests/functional/syntax/modules/test_exports.py @@ -30,7 +30,7 @@ def get_counter() -> uint256: assert e.value._message == "Cannot access `lib1` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib1` or `initializes: lib1` as a " + expected_hint = "add the line `uses: lib1` or `initializes: lib1` as a " expected_hint += "top-level statement to your contract" assert e.value.hint == expected_hint @@ -49,7 +49,7 @@ def test_exports_no_uses_variable(make_input_bundle): assert e.value._message == "Cannot access `lib1` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib1` or `initializes: lib1` as a " + expected_hint = "add the line `uses: lib1` or `initializes: lib1` as a " expected_hint += "top-level statement to your contract" assert e.value.hint == expected_hint diff --git a/tests/functional/syntax/modules/test_initializers.py b/tests/functional/syntax/modules/test_initializers.py index ead0fbcf6b..b49103ca38 100644 --- a/tests/functional/syntax/modules/test_initializers.py +++ b/tests/functional/syntax/modules/test_initializers.py @@ -355,7 +355,9 @@ def foo(): with pytest.raises(InitializerException) as e: compile_code(main, input_bundle=input_bundle) assert e.value._message == "module `lib1.vy` is used but never initialized!" - assert e.value._hint == "add `initializes: lib1` to the top level of your main contract" + assert ( + e.value._hint == "add the line `initializes: lib1` to the top level of your main contract" + ) def test_initializer_no_references(make_input_bundle): @@ -417,7 +419,7 @@ def foo(): assert e.value._message == "Cannot access `lib1` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib1` or `initializes: lib1` as a " + expected_hint = "add the line `uses: lib1` or `initializes: lib1` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -454,7 +456,7 @@ def __init__(): assert e.value._message == "Cannot access `lib1` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib1` or `initializes: lib1` as a " + expected_hint = "add the line `uses: lib1` or `initializes: lib1` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -495,7 +497,7 @@ def __init__(): assert e.value._message == "Cannot access `lib1` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib1` or `initializes: lib1` as a " + expected_hint = "add the line `uses: lib1` or `initializes: lib1` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -540,7 +542,7 @@ def __init__(): assert e.value._message == "Cannot access `lib1` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib1` or `initializes: lib1` as a " + expected_hint = "add the line `uses: lib1` or `initializes: lib1` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -575,7 +577,7 @@ def __init__(): assert e.value._message == "Cannot access `lib1` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib1` or `initializes: lib1` as a " + expected_hint = "add the line `uses: lib1` or `initializes: lib1` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -616,7 +618,7 @@ def __init__(): assert e.value._message == "Cannot access `lib1` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib1` or `initializes: lib1` as a " + expected_hint = "add the line `uses: lib1` or `initializes: lib1` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -660,7 +662,7 @@ def __init__(): assert e.value._message == "Cannot access `lib1` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib1` or `initializes: lib1` as a " + expected_hint = "add the line `uses: lib1` or `initializes: lib1` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -699,7 +701,7 @@ def foo(): assert e.value._message == "Cannot access `lib1` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib1` or `initializes: lib1` as a " + expected_hint = "add the line `uses: lib1` or `initializes: lib1` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -738,7 +740,7 @@ def foo(new_value: uint256): assert e.value._message == "Cannot access `lib2` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib2` or `initializes: lib2` as a " + expected_hint = "add the line `uses: lib2` or `initializes: lib2` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -780,7 +782,7 @@ def foo(new_value: uint256): assert e.value._message == "Cannot access `lib2` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib2` or `initializes: lib2` as a " + expected_hint = "add the line `uses: lib2` or `initializes: lib2` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -823,7 +825,7 @@ def foo(new_value: uint256): assert e.value._message == "Cannot access `lib2` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib2` or `initializes: lib2` as a " + expected_hint = "add the line `uses: lib2` or `initializes: lib2` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -857,7 +859,7 @@ def foo(new_value: uint256): assert e.value._message == "Cannot access `lib1` state!" + NONREENTRANT_NOTE - expected_hint = "add `uses: lib1` or `initializes: lib1` as a " + expected_hint = "add the line `uses: lib1` or `initializes: lib1` as a " expected_hint += "top-level statement to your contract" assert e.value._hint == expected_hint @@ -1122,7 +1124,10 @@ def __init__(): with pytest.raises(InitializerException) as e: compile_code(main, input_bundle=input_bundle) assert e.value._message == "tried to initialize `lib1`, but it is not in initializer list!" - assert e.value._hint == "add `initializes: lib1` as a top-level statement to your contract" + assert ( + e.value._hint + == "add the line `initializes: lib1` as a top-level statement to your contract" + ) def test_init_uninitialized_function2(make_input_bundle): @@ -1149,7 +1154,10 @@ def __init__(): with pytest.raises(InitializerException) as e: compile_code(main, input_bundle=input_bundle) assert e.value._message == "tried to initialize `lib1`, but it is not in initializer list!" - assert e.value._hint == "add `initializes: lib1` as a top-level statement to your contract" + assert ( + e.value._hint + == "add the line `initializes: lib1` as a top-level statement to your contract" + ) def test_noinit_initialized_function(make_input_bundle): @@ -1174,7 +1182,7 @@ def __init__(): with pytest.raises(InitializerException) as e: compile_code(main, input_bundle=input_bundle) assert e.value._message == "not initialized!" - assert e.value._hint == "add `lib1.__init__()` to your `__init__()` function" + assert e.value._hint == "add the line `lib1.__init__()` to your `__init__()` function" def test_noinit_initialized_function2(make_input_bundle): @@ -1197,7 +1205,7 @@ def __init__(): with pytest.raises(InitializerException) as e: compile_code(main, input_bundle=input_bundle) assert e.value._message == "not initialized!" - assert e.value._hint == "add `lib1.__init__()` to your `__init__()` function" + assert e.value._hint == "add the line `lib1.__init__()` to your `__init__()` function" def test_ownership_decl_errors_not_swallowed(make_input_bundle): @@ -1270,7 +1278,7 @@ def foo(): with pytest.raises(InitializerException) as e: compile_code(main, input_bundle=input_bundle) assert e.value._message == "`lib2` uses `lib3`, but it is not initialized with `lib3`" - assert e.value._hint == "add `lib3 := lib3` to its initializer list" + assert e.value._hint == "add the line `lib3 := lib3` to its initializer list" def test_hint_for_missing_initializer_when_no_import(make_input_bundle, chdir_tmp_path): @@ -1363,7 +1371,8 @@ def foo(): with pytest.raises(ImmutableViolation) as e: compile_code(main, input_bundle=nonreentrant_library_bundle) assert e.value._message == f"Cannot access `{lib}` state!" + NONREENTRANT_NOTE - hint = f"add `uses: {lib}` or `initializes: {lib}` as a top-level statement to your contract" + hint = f"add the line `uses: {lib}` or `initializes: {lib}` " + hint += "as a top-level statement to your contract" assert e.value._hint == hint assert e.value.annotations[0].lineno == 4 @@ -1381,7 +1390,8 @@ def foo(): compile_code(main, input_bundle=nonreentrant_library_bundle) assert e.value._message == f"Cannot access `{lib}` state!" + NONREENTRANT_NOTE - hint = f"add `uses: {lib}` or `initializes: {lib}` as a top-level statement to your contract" + hint = f"add the line `uses: {lib}` or `initializes: {lib}` " + hint += "as a top-level statement to your contract" assert e.value._hint == hint assert e.value.annotations[0].lineno == 6 diff --git a/vyper/semantics/analysis/global_.py b/vyper/semantics/analysis/global_.py index 23b45a1114..58486abec8 100644 --- a/vyper/semantics/analysis/global_.py +++ b/vyper/semantics/analysis/global_.py @@ -69,7 +69,7 @@ def _validate_global_initializes_constraint(module_t: ModuleT): module_str = "the top level of your main contract" else: module_str = f"`{module_t}`" - hint = f"add `initializes: {found_module.alias}` to {module_str}" + hint = f"add the line `initializes: {found_module.alias}` to {module_str}" err_list.append(InitializerException(msg, *uses, hint=hint)) diff --git a/vyper/semantics/analysis/local.py b/vyper/semantics/analysis/local.py index bdfc4d6629..d74919dd2c 100644 --- a/vyper/semantics/analysis/local.py +++ b/vyper/semantics/analysis/local.py @@ -276,8 +276,9 @@ def check_module_uses(node: vy_ast.ExprNode) -> Optional[ModuleInfo]: msg += " use of the `@nonreentrant` decorator is also considered" msg += " state access" - hint = f"please add the line `uses: {module_info.alias}` or " - hint += f"`initializes: {module_info.alias}` to your contract" + hint = f"add the line `uses: {module_info.alias}` or " + hint += f"`initializes: {module_info.alias}` as " + hint += "a top-level statement to your contract" raise ImmutableViolation(msg, hint=hint) # the leftmost- referenced module diff --git a/vyper/semantics/analysis/module.py b/vyper/semantics/analysis/module.py index d134d54d4a..d9ee769939 100644 --- a/vyper/semantics/analysis/module.py +++ b/vyper/semantics/analysis/module.py @@ -367,8 +367,8 @@ def validate_initialized_modules(self): if initialized_module.module_t not in should_initialize: msg = f"tried to initialize `{initialized_module.alias}`, " msg += "but it is not in initializer list!" - hint = f"please add the line `initializes: {initialized_module.alias}` " - hint += "to your contract" + hint = f"add the line `initializes: {initialized_module.alias}` " + hint += "as a top-level statement to your contract" raise InitializerException(msg, call_node.func, hint=hint) del should_initialize[initialized_module.module_t] @@ -378,7 +378,7 @@ def validate_initialized_modules(self): err_list = ExceptionList() for s in should_initialize.values(): msg = "not initialized!" - hint = f"add `{s.module_info.alias}.__init__()` to " + hint = f"add the line `{s.module_info.alias}.__init__()` to " hint += "your `__init__()` function" # grab the init function AST node for error message @@ -520,7 +520,7 @@ def visit_InitializesDecl(self, node): # it's `initializes: foo` instead of `initializes: foo[...]` hint = f"did you mean {module_ref.id}[{lhs} := {rhs}]?" else: - hint = f"add `{lhs} := {rhs}` to its initializer list" + hint = f"add the line `{lhs} := {rhs}` to its initializer list" raise InitializerException(msg, node, hint=hint) # note: try to refactor. not a huge fan of mutating the