From 6f6d1c5355d17e8c405c27e118ac86a3ac049439 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 21 May 2024 11:53:52 -0400 Subject: [PATCH 1/5] make `@internal` decorator optional the default is now internal. --- vyper/semantics/types/function.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vyper/semantics/types/function.py b/vyper/semantics/types/function.py index 7eab0958a6..c25a7b6935 100644 --- a/vyper/semantics/types/function.py +++ b/vyper/semantics/types/function.py @@ -755,9 +755,7 @@ def _parse_decorators( raise StructureException("Bad decorator syntax", decorator) if function_visibility is None: - raise FunctionDeclarationException( - f"Visibility must be set to one of: {', '.join(FunctionVisibility.values())}", funcdef - ) + function_visibility = FunctionVisibility.INTERNAL if state_mutability is None: # default to nonpayable From 3892474f3438acf3f8172460bbe876090e1ad14c Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 21 May 2024 11:58:36 -0400 Subject: [PATCH 2/5] update a couple tests --- tests/functional/codegen/features/test_internal_call.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/functional/codegen/features/test_internal_call.py b/tests/functional/codegen/features/test_internal_call.py index bec0b27d0d..0ee200ab6d 100644 --- a/tests/functional/codegen/features/test_internal_call.py +++ b/tests/functional/codegen/features/test_internal_call.py @@ -11,7 +11,6 @@ def test_selfcall_code(get_contract): selfcall_code = """ -@internal def _foo() -> int128: return 3 @@ -28,7 +27,6 @@ def bar() -> int128: def test_selfcall_code_2(get_contract, keccak): selfcall_code_2 = """ -@internal def _double(x: int128) -> int128: return x * 2 @@ -36,7 +34,6 @@ def _double(x: int128) -> int128: def returnten() -> int128: return self._double(5) -@internal def _hashy(x: bytes32) -> bytes32: return keccak256(x) From 20520476a460f8655d29ae708f005878f83138b4 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 21 May 2024 12:56:06 -0400 Subject: [PATCH 3/5] remove dead tests --- .../codegen/features/decorators/test_public.py | 9 --------- .../exceptions/test_function_declaration_exception.py | 10 ---------- 2 files changed, 19 deletions(-) diff --git a/tests/functional/codegen/features/decorators/test_public.py b/tests/functional/codegen/features/decorators/test_public.py index f9a1e52e7f..054e0f1e31 100644 --- a/tests/functional/codegen/features/decorators/test_public.py +++ b/tests/functional/codegen/features/decorators/test_public.py @@ -10,12 +10,3 @@ def foo(): """ assert_compile_failed(lambda: get_contract(code), FunctionDeclarationException) - - -def test_invalid_if_visibility_isnt_declared(assert_compile_failed, get_contract): - code = """ -def foo(): - x: uint256 = 1 -""" - - assert_compile_failed(lambda: get_contract(code), FunctionDeclarationException) diff --git a/tests/functional/syntax/exceptions/test_function_declaration_exception.py b/tests/functional/syntax/exceptions/test_function_declaration_exception.py index 878c7f3e29..b3966661fa 100644 --- a/tests/functional/syntax/exceptions/test_function_declaration_exception.py +++ b/tests/functional/syntax/exceptions/test_function_declaration_exception.py @@ -19,16 +19,6 @@ def foo() -> int128: pass """, """ -def foo() -> int128: - q: int128 = 111 - return q - """, - """ -q: int128 -def foo() -> int128: - return self.q - """, - """ @external def test_func() -> int128: return (1, 2) From 9f679b285775d9a70889627a803c6574adb2f8d1 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sat, 25 May 2024 07:29:19 -0400 Subject: [PATCH 4/5] update signature --- vyper/semantics/types/function.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/vyper/semantics/types/function.py b/vyper/semantics/types/function.py index 979ed3e97e..a76a6d8b32 100644 --- a/vyper/semantics/types/function.py +++ b/vyper/semantics/types/function.py @@ -349,8 +349,6 @@ def from_vyi(cls, funcdef: vy_ast.FunctionDef) -> "ContractFunctionT": "function body in an interface can only be `...`!", funcdef ) - assert function_visibility is not None # mypy hint - return cls( funcdef.name, positional_args, @@ -419,9 +417,6 @@ def from_FunctionDef(cls, funcdef: vy_ast.FunctionDef) -> "ContractFunctionT": "Constructor may not use default arguments", funcdef.args.defaults[0] ) - # sanity check - assert function_visibility is not None - return cls( funcdef.name, positional_args, @@ -702,7 +697,7 @@ def _parse_return_type(funcdef: vy_ast.FunctionDef) -> Optional[VyperType]: def _parse_decorators( funcdef: vy_ast.FunctionDef, -) -> tuple[Optional[FunctionVisibility], StateMutability, bool]: +) -> tuple[FunctionVisibility, StateMutability, bool]: function_visibility = None state_mutability = None nonreentrant_node = None @@ -767,8 +762,6 @@ def _parse_decorators( if state_mutability == StateMutability.PURE and nonreentrant_node is not None: raise StructureException("Cannot use reentrancy guard on pure functions", nonreentrant_node) - # assert function_visibility is not None # mypy - # assert state_mutability is not None # mypy nonreentrant = nonreentrant_node is not None return function_visibility, state_mutability, nonreentrant From 0a48a56d255d91fbc3853f6ebfca59f4a2d0371a Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sat, 25 May 2024 08:16:00 -0400 Subject: [PATCH 5/5] update an error message --- vyper/semantics/types/function.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vyper/semantics/types/function.py b/vyper/semantics/types/function.py index a76a6d8b32..ae913b097c 100644 --- a/vyper/semantics/types/function.py +++ b/vyper/semantics/types/function.py @@ -403,8 +403,7 @@ def from_FunctionDef(cls, funcdef: vy_ast.FunctionDef) -> "ContractFunctionT": ) if function_visibility != FunctionVisibility.DEPLOY: raise FunctionDeclarationException( - f"Constructor must be marked as `@deploy`, not `@{function_visibility}`", - funcdef, + "Constructor must be marked as `@deploy`", funcdef ) if return_type is not None: raise FunctionDeclarationException(