@@ -97,6 +97,7 @@ def __init__(
97
97
state_mutability : StateMutability ,
98
98
from_interface : bool = False ,
99
99
nonreentrant : bool = False ,
100
+ inline : bool = False ,
100
101
ast_def : Optional [vy_ast .VyperNode ] = None ,
101
102
) -> None :
102
103
super ().__init__ ()
@@ -109,6 +110,7 @@ def __init__(
109
110
self .mutability = state_mutability
110
111
self .nonreentrant = nonreentrant
111
112
self .from_interface = from_interface
113
+ self .inline = inline
112
114
113
115
# sanity check, nonreentrant used to be Optional[str]
114
116
assert isinstance (self .nonreentrant , bool )
@@ -250,6 +252,7 @@ def from_abi(cls, abi: dict) -> "ContractFunctionT":
250
252
from_interface = True ,
251
253
function_visibility = FunctionVisibility .EXTERNAL ,
252
254
state_mutability = StateMutability .from_abi (abi ),
255
+ inline = False ,
253
256
)
254
257
255
258
@classmethod
@@ -309,6 +312,7 @@ def from_InterfaceDef(cls, funcdef: vy_ast.FunctionDef) -> "ContractFunctionT":
309
312
state_mutability ,
310
313
from_interface = True ,
311
314
nonreentrant = False ,
315
+ inline = False ,
312
316
ast_def = funcdef ,
313
317
)
314
318
@@ -327,14 +331,14 @@ def from_vyi(cls, funcdef: vy_ast.FunctionDef) -> "ContractFunctionT":
327
331
-------
328
332
ContractFunctionT
329
333
"""
330
- function_visibility , state_mutability , nonreentrant = _parse_decorators (funcdef )
334
+ function_visibility , state_mutability , nonreentrant , inline = _parse_decorators (funcdef )
331
335
332
- if nonreentrant :
336
+ if nonreentrant or inline :
333
337
# TODO: refactor so parse_decorators returns the AST location
334
- decorator = next (d for d in funcdef .decorator_list if d .id == "nonreentrant" )
335
- raise FunctionDeclarationException (
336
- "`@nonreentrant` not allowed in interfaces" , decorator
338
+ decorator = next (
339
+ d for d in funcdef .decorator_list if d .id in ("nonreentrant" , "inline" )
337
340
)
341
+ raise FunctionDeclarationException (f"`@{ d .id } ` not allowed in interfaces" , decorator )
338
342
339
343
# it's redundant to specify visibility in vyi - always should be external
340
344
if function_visibility is None :
@@ -378,6 +382,7 @@ def from_vyi(cls, funcdef: vy_ast.FunctionDef) -> "ContractFunctionT":
378
382
state_mutability ,
379
383
from_interface = True ,
380
384
nonreentrant = nonreentrant ,
385
+ inline = False ,
381
386
ast_def = funcdef ,
382
387
)
383
388
@@ -395,7 +400,7 @@ def from_FunctionDef(cls, funcdef: vy_ast.FunctionDef) -> "ContractFunctionT":
395
400
-------
396
401
ContractFunctionT
397
402
"""
398
- function_visibility , state_mutability , nonreentrant = _parse_decorators (funcdef )
403
+ function_visibility , state_mutability , nonreentrant , inline = _parse_decorators (funcdef )
399
404
400
405
# it's redundant to specify internal visibility - it's implied by not being external
401
406
if function_visibility is None :
@@ -453,6 +458,7 @@ def from_FunctionDef(cls, funcdef: vy_ast.FunctionDef) -> "ContractFunctionT":
453
458
state_mutability ,
454
459
from_interface = False ,
455
460
nonreentrant = nonreentrant ,
461
+ inline = inline ,
456
462
ast_def = funcdef ,
457
463
)
458
464
@@ -726,10 +732,11 @@ def _parse_return_type(funcdef: vy_ast.FunctionDef) -> Optional[VyperType]:
726
732
727
733
def _parse_decorators (
728
734
funcdef : vy_ast .FunctionDef ,
729
- ) -> tuple [Optional [FunctionVisibility ], StateMutability , bool ]:
735
+ ) -> tuple [Optional [FunctionVisibility ], StateMutability , bool , bool ]:
730
736
function_visibility = None
731
737
state_mutability = None
732
738
nonreentrant_node = None
739
+ inline_node = None
733
740
734
741
for decorator in funcdef .decorator_list :
735
742
if isinstance (decorator , vy_ast .Call ):
@@ -747,6 +754,12 @@ def _parse_decorators(
747
754
748
755
nonreentrant_node = decorator
749
756
757
+ elif decorator .get ("id" ) == "inline" :
758
+ if inline_node is not None :
759
+ raise StructureException ("inline decorator is already set" , inline_node )
760
+
761
+ inline_node = decorator
762
+
750
763
elif isinstance (decorator , vy_ast .Name ):
751
764
if FunctionVisibility .is_valid_value (decorator .id ):
752
765
if function_visibility is not None :
@@ -786,7 +799,8 @@ def _parse_decorators(
786
799
raise StructureException ("Cannot use reentrancy guard on pure functions" , nonreentrant_node )
787
800
788
801
nonreentrant = nonreentrant_node is not None
789
- return function_visibility , state_mutability , nonreentrant
802
+ inline = inline_node is not None
803
+ return function_visibility , state_mutability , nonreentrant , inline
790
804
791
805
792
806
def _parse_args (
0 commit comments