Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[lang]!: make internal decorator optional #4040

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions tests/functional/codegen/features/decorators/test_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 0 additions & 3 deletions tests/functional/codegen/features/test_internal_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

def test_selfcall_code(get_contract):
selfcall_code = """
@internal
def _foo() -> int128:
return 3

Expand All @@ -28,15 +27,13 @@ def bar() -> int128:

def test_selfcall_code_2(get_contract, keccak):
selfcall_code_2 = """
@internal
def _double(x: int128) -> int128:
return x * 2

@external
def returnten() -> int128:
return self._double(5)

@internal
def _hashy(x: bytes32) -> bytes32:
return keccak256(x)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 3 additions & 13 deletions vyper/semantics/types/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -405,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(
Expand All @@ -419,9 +416,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,
Expand Down Expand Up @@ -702,7 +696,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
Expand Down Expand Up @@ -758,9 +752,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
Expand All @@ -769,8 +761,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

Expand Down
Loading