Skip to content
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
18 changes: 9 additions & 9 deletions src/pdl/pdl_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,6 @@ def process_block(
return result, background, scope, trace


def context_in_contribute(block: AdvancedBlockType) -> bool:
if ContributeTarget.CONTEXT.value in block.contribute:
return True
if get_contribute_context_value(block.contribute) is not None:
return True
return False


# A start-end time wrapper around `process_advanced_block`
def process_advanced_block_timed(
state: InterpreterState,
Expand Down Expand Up @@ -520,7 +512,7 @@ def process_advanced_block( # noqa:C901
result_with_type_checking,
spec=block.spec,
msg="Type errors during spec checking:",
loc=loc,
loc=append(loc, "spec"),
trace=trace,
)
result = lazy_apply(checker, result)
Expand Down Expand Up @@ -589,6 +581,14 @@ def process_advanced_block( # noqa:C901
return result, background, new_scope, trace


def context_in_contribute(block: AdvancedBlockType) -> bool:
if ContributeTarget.CONTEXT.value in block.contribute:
return True
if get_contribute_context_value(block.contribute) is not None:
return True
return False


ResultWithTypeCheckingT = TypeVar("ResultWithTypeCheckingT")


Expand Down
5 changes: 5 additions & 0 deletions tests/data/line/hello32.pdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defs:
x:
data: 1
spec: string
text: ${x}
1 change: 1 addition & 0 deletions tests/test_examples_run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ expected_runtime_error:
- tests/data/line/hello28.pdl
- tests/data/line/hello29.pdl
- tests/data/line/hello30.pdl
- tests/data/line/hello32.pdl
38 changes: 26 additions & 12 deletions tests/test_line_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def test_line1(capsys: CaptureFixture[str]):
"file": "tests/data/line/hello3.pdl",
"errors": [
"",
"tests/data/line/hello3.pdl:6 - Type errors during spec checking:",
"tests/data/line/hello3.pdl:6 - World! should be of type <class 'int'>",
"tests/data/line/hello3.pdl:7 - Type errors during spec checking:",
"tests/data/line/hello3.pdl:7 - World! should be of type <class 'int'>",
],
}

Expand Down Expand Up @@ -100,8 +100,8 @@ def test_line8(capsys: CaptureFixture[str]):
"file": "tests/data/line/hello9.pdl",
"errors": [
"",
"tests/data/line/hello9.pdl:3 - Type errors during spec checking:",
"tests/data/line/hello9.pdl:3 - hello should be of type <class 'int'>",
"tests/data/line/hello9.pdl:4 - Type errors during spec checking:",
"tests/data/line/hello9.pdl:4 - hello should be of type <class 'int'>",
],
}

Expand Down Expand Up @@ -140,8 +140,8 @@ def test_line11(capsys: CaptureFixture[str]):
"file": "tests/data/line/hello12.pdl",
"errors": [
"",
"tests/data/line/hello12.pdl:9 - Type errors during spec checking:",
"tests/data/line/hello12.pdl:9 - How are you? should be of type <class 'bool'>",
"tests/data/line/hello12.pdl:11 - Type errors during spec checking:",
"tests/data/line/hello12.pdl:11 - How are you? should be of type <class 'bool'>",
],
}

Expand All @@ -154,8 +154,8 @@ def test_line12(capsys: CaptureFixture[str]):
"file": "tests/data/line/hello13.pdl",
"errors": [
"",
"tests/data/line/hello13.pdl:9 - Type errors during spec checking:",
"tests/data/line/hello13.pdl:9 - 1 should be of type <class 'str'>",
"tests/data/line/hello13.pdl:12 - Type errors during spec checking:",
"tests/data/line/hello13.pdl:12 - 1 should be of type <class 'str'>",
],
}

Expand Down Expand Up @@ -195,8 +195,8 @@ def test_line15(capsys: CaptureFixture[str]):
"file": "tests/data/line/hello16.pdl",
"errors": [
"",
"tests/data/line/hello16.pdl:8 - Type errors during spec checking:",
"tests/data/line/hello16.pdl:8 - 30 should be of type <class 'str'>",
"tests/data/line/hello16.pdl:10 - Type errors during spec checking:",
"tests/data/line/hello16.pdl:10 - 30 should be of type <class 'str'>",
],
}

Expand All @@ -209,8 +209,8 @@ def test_line16(capsys: CaptureFixture[str]):
"file": "tests/data/line/hello17.pdl",
"errors": [
"",
"tests/data/line/hello17.pdl:3 - Type errors during spec checking:",
"tests/data/line/hello17.pdl:3 - hello should be of type <class 'int'>",
"tests/data/line/hello17.pdl:4 - Type errors during spec checking:",
"tests/data/line/hello17.pdl:4 - hello should be of type <class 'int'>",
],
}

Expand Down Expand Up @@ -405,3 +405,17 @@ def test_line30(capsys: CaptureFixture[str]):

def test_line31(capsys: CaptureFixture[str]):
do_test(line31, capsys)


line32 = {
"file": "tests/data/line/hello32.pdl",
"errors": [
"",
"tests/data/line/hello32.pdl:4 - Type errors during spec checking:",
"tests/data/line/hello32.pdl:4 - 1 should be of type <class 'str'>",
],
}


def test_line32(capsys: CaptureFixture[str]):
do_test(line32, capsys)
2 changes: 1 addition & 1 deletion tests/test_runtime_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_type_result():
exec_str(prog_str)
assert (
str(exc.value.message)
== "Type errors during spec checking:\nline 0 - Hello should be of type <class 'int'>"
== "Type errors during spec checking:\nline 3 - Hello should be of type <class 'int'>"
)


Expand Down