Skip to content

Commit

Permalink
fix: pytest trace shows wrong lineno [APE-1388] (#1657)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Sep 11, 2023
1 parent 73f981f commit 0d07ca8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/ape/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,10 @@ def _get_custom_python_traceback(
continue

depth = exec_item.depth
lineno = exec_item.begin_lineno

# NOTE: Use the last lineno executed as "the line number".
lineno = exec_item.begin_lineno if exec_item.end_lineno is None else exec_item.end_lineno

if lineno is None:
idx -= 1
continue
Expand Down
10 changes: 5 additions & 5 deletions src/ape/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ def from_event(
from ape import convert
from ape.utils.abi import LogInputABICollection, is_dynamic_sized_type

event = getattr(event, "abi", event)
event_abi: EventABI = getattr(event, "abi", event) # type: ignore[assignment]
search_topics = search_topics or {}
topic_filter: List[Optional[HexStr]] = [encode_hex(keccak(text=event.selector))]
abi_inputs = LogInputABICollection(event)
topic_filter: List[Optional[HexStr]] = [encode_hex(keccak(text=event_abi.selector))]
abi_inputs = LogInputABICollection(event_abi)

def encode_topic_value(abi_type, value):
if isinstance(value, (list, tuple)):
Expand All @@ -190,7 +190,7 @@ def encode_topic_value(abi_type, value):
invalid_topics = set(search_topics) - set(topic_names)
if invalid_topics:
raise ValueError(
f"{event.name} defines {', '.join(topic_names)} as indexed topics, "
f"{event_abi.name} defines {', '.join(topic_names)} as indexed topics, "
f"but you provided {', '.join(invalid_topics)}"
)

Expand All @@ -200,7 +200,7 @@ def encode_topic_value(abi_type, value):

return cls(
addresses=addresses or [],
events=[event],
events=[event_abi],
topic_filter=topic_filter,
start_block=start_block,
stop_block=stop_block,
Expand Down

0 comments on commit 0d07ca8

Please sign in to comment.