Skip to content

Commit b401594

Browse files
committed
fix: fix path sum iii json
1 parent 6139852 commit b401594

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

.claude/commands/test-quality-assurance.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ rm -rf leetcode/{problem_name}_backup
3838
-**NEVER modify helpers.py manually** - let regeneration handle it
3939
-**NEVER skip ty verification** - this is the main CI issue
4040
-**NEVER assume tests will pass** - they may fail if solution is incomplete
41+
-**NEVER use `null` in JSON templates** - use `None` for Python None values
4142

4243
### 4. What to Do
4344

4445
-**ALWAYS use `bake p-gen -p {problem_name} -f`** for regeneration
4546
-**ALWAYS verify ty passes** before considering task complete
4647
-**ALWAYS restore original solution** after regeneration
4748
-**ALWAYS check JSON template** if ty fails (look for `assert_assert_` bugs)
49+
-**ALWAYS use `None` not `null` in JSON templates** for Python None values
4850

4951
## Test Case Standards
5052

@@ -57,6 +59,9 @@ rm -rf leetcode/{problem_name}_backup
5759

5860
### JSON Format
5961

62+
- **CRITICAL**: Use `None` NOT `null` for Python None values in test cases
63+
- JSON templates use `None` directly: `"[1, None, 2]"` NOT `"[1, null, 2]"`
64+
- This ensures generated Python code passes linting (ruff/ty check for undefined name `null`)
6065
- Use single quotes for Python strings: `'hello'` not `"hello"`
6166
- Follow existing parametrize format
6267
- Ensure valid Python list syntax in test_cases field
@@ -109,6 +114,20 @@ bake p-gen -p {problem_name} -f
109114
**Expected**: Tests may fail if solution is incomplete (returns 0 or placeholder)
110115
**Action**: This is normal - focus on ty passing, not test results
111116

117+
### Issue: `null` vs `None` in JSON Templates
118+
119+
**Cause**: JSON template uses `null` which causes linting errors in generated Python code
120+
121+
- Error: `F821 Undefined name 'null'` from ruff/ty
122+
- Generated test files contain `null` which is not valid Python
123+
124+
**Solution**: Update JSON template to use `None` instead of `null`
125+
126+
- Change: `"([1, null, 2], 3, 1)"``"([1, None, 2], 3, 1)"`
127+
- This applies to `test_cases` list and `playground_setup` fields
128+
- After fixing JSON, regenerate with `bake p-gen -p {problem_name} -f`
129+
- Generated code will now pass linting without manual edits
130+
112131
## Success Criteria
113132

114133
-**ty passes** with no errors (CRITICAL for CI)

leetcode/path_sum_iii/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ The path does not need to start or end at the root or a leaf, but it must go dow
1919
![Example 1](https://assets.leetcode.com/uploads/2021/04/09/pathsum3-1-tree.jpg)
2020

2121
```
22-
Input: root = [10,5,-3,3,2,null,11,3,-2,null,1], targetSum = 8
22+
Input: root = [10,5,-3,3,2,None,11,3,-2,None,1], targetSum = 8
2323
Output: 3
2424
Explanation: The paths that sum to 8 are shown.
2525
```
2626

2727
### Example 2:
2828

2929
```
30-
Input: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22
30+
Input: root = [5,4,8,11,None,13,4,7,2,None,None,5,1], targetSum = 22
3131
Output: 3
3232
```
3333

src/leetcode_py/cli/resources/leetcode/json/problems/path_sum_iii.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"_readme_examples": {
1111
"list": [
1212
{
13-
"content": "![Example 1](https://assets.leetcode.com/uploads/2021/04/09/pathsum3-1-tree.jpg)\n\n```\nInput: root = [10,5,-3,3,2,null,11,3,-2,null,1], targetSum = 8\nOutput: 3\nExplanation: The paths that sum to 8 are shown.\n```"
13+
"content": "![Example 1](https://assets.leetcode.com/uploads/2021/04/09/pathsum3-1-tree.jpg)\n\n```\nInput: root = [10,5,-3,3,2,None,11,3,-2,None,1], targetSum = 8\nOutput: 3\nExplanation: The paths that sum to 8 are shown.\n```"
1414
},
1515
{
16-
"content": "```\nInput: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22\nOutput: 3\n```"
16+
"content": "```\nInput: root = [5,4,8,11,None,13,4,7,2,None,None,5,1], targetSum = 22\nOutput: 3\n```"
1717
}
1818
]
1919
},
@@ -47,7 +47,7 @@
4747
"list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }]
4848
},
4949
"playground_imports": "from helpers import run_path_sum, assert_path_sum\nfrom solution import Solution\nfrom leetcode_py import TreeNode",
50-
"playground_setup": "# Example test case\nroot_list: list[int | None] = [10,5,-3,3,2,null,11,3,-2,null,1]\ntarget_sum = 8\nexpected = 3",
50+
"playground_setup": "# Example test case\nroot_list: list[int | None] = [10,5,-3,3,2,None,11,3,-2,None,1]\ntarget_sum = 8\nexpected = 3",
5151
"playground_run": "result = run_path_sum(Solution, root_list, target_sum)\nresult",
5252
"playground_assert": "assert_path_sum(result, expected)",
5353
"_test_methods": {
@@ -58,28 +58,28 @@
5858
"parametrize": "root_list, target_sum, expected",
5959
"test_cases": {
6060
"list": [
61-
"([10,5,-3,3,2,null,11,3,-2,null,1], 8, 3)",
62-
"([5,4,8,11,null,13,4,7,2,null,null,5,1], 22, 3)",
61+
"([10,5,-3,3,2,None,11,3,-2,None,1], 8, 3)",
62+
"([5,4,8,11,None,13,4,7,2,None,None,5,1], 22, 3)",
6363
"([], 1, 0)",
6464
"([1], 1, 1)",
6565
"([1], 0, 0)",
66-
"([1,2], 3, 2)",
66+
"([1,2], 3, 1)",
6767
"([1,2,3], 3, 2)",
6868
"([1,2,3], 5, 0)",
6969
"([1,-2,3], 1, 1)",
70-
"([1,-2,3], 2, 1)",
70+
"([1,-2,3], 2, 0)",
7171
"([1,-2,-3], -3, 1)",
7272
"([0,1,1], 1, 4)",
7373
"([1,0,1,0,1], 1, 6)",
7474
"([0], 0, 1)",
75-
"([-3,-2,1,1,1], -1, 4)"
75+
"([-3,-2,1,1,1], -1, 2)"
7676
]
7777
},
7878
"body": " result = run_path_sum(Solution, root_list, target_sum)\n assert_path_sum(result, expected)"
7979
}
8080
]
8181
},
82-
"playground_test_case": "root_list: list[int | None] = [10,5,-3,3,2,null,11,3,-2,null,1]\ntarget_sum = 8",
82+
"playground_test_case": "root_list: list[int | None] = [10,5,-3,3,2,None,11,3,-2,None,1]\ntarget_sum = 8",
8383
"playground_execution": "result = run_path_sum(Solution, root_list, target_sum)",
8484
"playground_assertion": "assert_path_sum(result, 3)"
8585
}

0 commit comments

Comments
 (0)