Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

docstrings.py 566 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  1. import ast
  2. def get_docstrings_from_code(codeblock: str, delimeter='<|||>') -> str:
  3. """
  4. Args:
  5. delimeter (str):
  6. """
  7. docstrings = []
  8. try:
  9. tree = ast.parse(codeblock)
  10. for child in ast.iter_child_nodes(tree):
  11. try:
  12. docstrings.append(ast.get_docstring(child))
  13. except:
  14. pass
  15. return (delimeter).join(docstrings)
  16. except:
  17. return '<ast parse error>'
  18. def bad_way_to_do_stuff(func, *args):
  19. try:
  20. return func(*args)
  21. except:
  22. return -1
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...