Skip to content

Commit

Permalink
chore: describe ast_helpers exposed in Python challenges (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
gikf authored Oct 28, 2024
1 parent d38ba95 commit 8b4fd3f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/content/docs/curriculum-help.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ To check the return value of `__str__` you would write:
});
```
AST-based helpers are also exposed in the Python challenges in `ast_helpers` module. `_Node` class corresponds to the `ast_helpers.Node`:
```py
import ast_helpers

code = '''
class Spam:
def __str__(self):
return 'spam!'
'''

print(
ast_helpers.Node(code)
.find_class("Spam")
.find_function("__str__")
.has_return("'spam!'")
)
```
### Methods
The exstensive list of methods for parsing and testing Python code is available [here](https://opensource.freecodecamp.org/curriculum-helpers/python.html#ast-based-helpers)

0 comments on commit 8b4fd3f

Please sign in to comment.