feat: add example of how to use python helpers (#53908)

This commit is contained in:
Oliver Eyton-Williams 2024-02-29 12:48:35 +01:00 committed by GitHub
parent fab633088f
commit 6da2e71327
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 58 additions and 1 deletions

View File

@ -27,6 +27,10 @@
{
"id": "64b171849f925b0773aa434c",
"title": "Step 4"
},
{
"id": "65df3afd233057f6a620a860",
"title": "Step 5"
}
]
}
}

View File

@ -0,0 +1,53 @@
---
id: 65df3afd233057f6a620a860
title: Step 5
challengeType: 20
dashedName: step-5
---
# --description--
This shows how the helper functions can be used to analyze a learner's class definitions
# --instructions--
We can just find the class definition inside Python, return it to the JavaScript, and then check if it contains the string "pass".
If we need something more reliable, we can expand the helpers to check for pass statements specifically. This would be useful if say, we wanted to write classes containing, say, passengers.
# --hints--
`TreeNode` should not contain any `pass` statements.
```js
({ test: () => {
const pyClassStr = runPython(`str(_Node(_code).find_class("TreeNode"))`);
assert.notInclude(pyClassStr, "pass")
}})
```
# --seed--
## --seed-contents--
```py
--fcc-editable-region--
class TreeNode:
pass
class Trap:
pass
--fcc-editable-region--
```
# --solutions--
```py
class TreeNode:
def __init__(self, thing):
self.thing = thing
class Trap:
pass
```