core: add AST-based linter for undeclared state reads in function-bas…#656
core: add AST-based linter for undeclared state reads in function-bas…#656Smitaambiger wants to merge 3 commits intoapache:mainfrom
Conversation
|
Initial implementation for AST-based undeclared state read validation. Currently implemented as a hard ValueError at action construction time. Happy to adjust:
Looking forward to feedback. |
burr/core/action.py
Outdated
| return | ||
|
|
||
|
|
||
| import textwrap |
There was a problem hiding this comment.
imports should be top level
| def test_undeclared_state_read_raises_error(): | ||
| with pytest.raises(ValueError): | ||
|
|
||
| @action(reads=["foo"], writes=[]) | ||
| def bad_action(state: State): | ||
| x = state["bar"] | ||
| return {}, state | ||
|
|
||
|
|
||
| def test_declared_state_read_passes(): | ||
| @action(reads=["foo"], writes=[]) | ||
| def good_action(state: State): | ||
| x = state["foo"] | ||
| return {}, state |
There was a problem hiding this comment.
can you add a test for multiple missing keys interleaved with non-missing keys please?
There was a problem hiding this comment.
you'll also need a test to ensure this doesn't impact pydantic typed state.
There was a problem hiding this comment.
and this test should be housed under test_action.py
skrawcz
left a comment
There was a problem hiding this comment.
good start, a few things to add.
|
@skrawcz ,Thanks for the detailed feedback! Addressed the requested changes:
Core tests are passing locally and CI should reflect the same. Please let me know if any further adjustments are needed. |
Closes #407
This PR adds AST-based validation for undeclared state reads in function-based actions.
What this does
inspect.getsourcestate["<literal>"]accessesreads=[...]ValueErrorif undeclared keys are accessedWhy
Prevents silent bugs caused by accessing state keys that were not declared in
reads, enforcing stricter action correctness.Tests