@@ -50,7 +50,7 @@ def exec_python(source):
5050register_executor ("python" , exec_python )
5151
5252
53- def get_codeblock_members (* classes ):
53+ def get_codeblock_members (* classes , lang = "python" ):
5454 """
5555 Grabs the docstrings of any methods of any classes that are passed in.
5656 """
@@ -61,7 +61,7 @@ def get_codeblock_members(*classes):
6161 for name , member in inspect .getmembers (cl ):
6262 if member .__doc__ :
6363 results .append (member )
64- return [m for m in results if len (grab_code_blocks (m .__doc__ )) > 0 ]
64+ return [m for m in results if len (grab_code_blocks (m .__doc__ , lang = lang )) > 0 ]
6565
6666
6767def check_codeblock (block , lang = "python" ):
@@ -76,7 +76,7 @@ def check_codeblock(block, lang="python"):
7676 """
7777 first_line = block .split ("\n " )[0 ]
7878 if lang :
79- if first_line [3 :] != lang :
79+ if first_line . lstrip () [3 :] != lang :
8080 return ""
8181 return "\n " .join (block .split ("\n " )[1 :])
8282
@@ -104,12 +104,14 @@ def grab_code_blocks(docstring, lang="python"):
104104 block += line + "\n "
105105 return [textwrap .dedent (c ) for c in codeblocks if c != "" ]
106106
107+
107108def format_docstring (docstring ):
108109 """Formats docstring to be able to successfully go through dedent."""
109110 if docstring [:1 ] != "\n " :
110111 return f"\n { docstring } "
111112 return docstring
112113
114+
113115def check_docstring (obj , lang = "" ):
114116 """
115117 Given a function, test the contents of the docstring.
0 commit comments