Skip to content

Commit

Permalink
fix: abstract methods can still have implementations, which can be ca…
Browse files Browse the repository at this point in the history
…lled via super
  • Loading branch information
achidlow committed Sep 3, 2024
1 parent 40777ee commit 9615467
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 43 deletions.
49 changes: 16 additions & 33 deletions src/puyapy/awst_build/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,39 +348,22 @@ def _handle_method(
# since we checked we're only handling instance methods, should be at least one
# argument to function - ie self
self._error(f"{func_def.name} should take a self parameter", func_loc)
match func_def.abstract_status:
case mypy.nodes.NOT_ABSTRACT:
if arc4_method_data is not None:
self.context.add_arc4_method_data(self.cref, func_def.name, arc4_method_data)
return lambda ctx: FunctionASTConverter.convert(
ctx,
func_def=func_def,
source_location=source_location,
contract_method_info=ContractMethodInfo(
contract_type=self.typ,
type_info=self.class_def.info,
arc4_method_data=arc4_method_data,
cref=self.cref,
),
)
case mypy.nodes.IMPLICITLY_ABSTRACT:
# TODO: should we have a placeholder item instead? need to handle via super() if so
self.context.info(
f"Skipping (implicitly) abstract method {func_def.name}",
func_loc,
)
return None
case mypy.nodes.IS_ABSTRACT:
# TODO: should we have a placeholder item instead? need to handle via super() if so
self.context.info(
f"Skipping abstract method {func_def.name}",
func_loc,
)
return None
case _ as unknown_value:
raise InternalError(
f"Unknown value for abstract_status: {unknown_value}", func_loc
)
if func_def.is_trivial_body:
logger.debug(f"skipping trivial method {func_def.name}", location=func_loc)
return None
if arc4_method_data is not None:
self.context.add_arc4_method_data(self.cref, func_def.name, arc4_method_data)
return lambda ctx: FunctionASTConverter.convert(
ctx,
func_def=func_def,
source_location=source_location,
contract_method_info=ContractMethodInfo(
contract_type=self.typ,
type_info=self.class_def.info,
arc4_method_data=arc4_method_data,
cref=self.cref,
),
)

def visit_block(self, o: mypy.nodes.Block) -> None:
raise InternalError("shouldn't get here", self._location(o))
Expand Down
18 changes: 9 additions & 9 deletions test_cases/iteration/puya.log
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
debug: PuyaOptions(paths=['iteration'], output_teal=True, output_arc32=True, output_client=True, output_awst=True, output_ssa_ir=True, output_optimization_ir=True, output_destructured_ir=True, output_memory_ir=True, output_bytecode=True, match_algod_bytecode=False, debug_level=1, optimization_level=1, log_level=<LogLevel.debug: 10>, target_avm_version=10, cli_template_definitions=[], template_vars_prefix='TMPL_', locals_coalescing_strategy=<LocalsCoalescingStrategy.root_operand: 'root_operand'>)
info: Found python prefix: <git root>/.venv
iteration/base.py:38 info: Skipping abstract method test_forwards
iteration/base.py:42 info: Skipping abstract method test_reversed
iteration/base.py:46 info: Skipping abstract method test_forwards_with_forwards_index
iteration/base.py:50 info: Skipping abstract method test_forwards_with_reverse_index
iteration/base.py:54 info: Skipping abstract method test_reverse_with_forwards_index
iteration/base.py:58 info: Skipping abstract method test_reverse_with_reverse_index
iteration/base.py:62 info: Skipping abstract method test_empty
iteration/base.py:66 info: Skipping abstract method test_break
iteration/base.py:70 info: Skipping abstract method test_tuple_target
iteration/base.py:38 debug: skipping trivial method test_forwards
iteration/base.py:42 debug: skipping trivial method test_reversed
iteration/base.py:46 debug: skipping trivial method test_forwards_with_forwards_index
iteration/base.py:50 debug: skipping trivial method test_forwards_with_reverse_index
iteration/base.py:54 debug: skipping trivial method test_reverse_with_forwards_index
iteration/base.py:58 debug: skipping trivial method test_reverse_with_reverse_index
iteration/base.py:62 debug: skipping trivial method test_empty
iteration/base.py:66 debug: skipping trivial method test_break
iteration/base.py:70 debug: skipping trivial method test_tuple_target
debug: Sealing block@0: // L4
debug: Terminated block@0: // L4
debug: Looking for 'start' in an unsealed block creating an incomplete Phi: block@1: // while_top_L11
Expand Down
2 changes: 1 addition & 1 deletion tests/test_expected_output/module.test
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class MyContractBase(Contract, abc.ABC):

@abc.abstractmethod
@subroutine
def get_value(self) -> UInt64: ... ## N: Skipping abstract method get_value
def get_value(self) -> UInt64: ...


## path: main.py
Expand Down

0 comments on commit 9615467

Please sign in to comment.