Skip to content

Commit 4312ed7

Browse files
committed
Support display no docstring
So far an empty docstring was shown when no docstring was specified. The logic for displaying the docstring is in the package widget-code-input and needed to be updatet to support no docstring.
1 parent 99a24f6 commit 4312ed7

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ classifiers = [
3030
dependencies = [
3131
"ipywidgets>=8.0.0",
3232
"numpy<2.0.0",
33-
"widget_code_input>=4.0.13",
33+
"widget_code_input @ git+https://github.com/agoscinski/widget-code-input@remove-docstring",
3434
"matplotlib",
3535
"termcolor"
3636
]

src/scwidgets/code/_widget_code_input.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def __init__(
7171
if function_name is None:
7272
raise ValueError("function_name must be given if no function is given.")
7373
function_parameters = "" if function_parameters is None else function_parameters
74-
docstring = "\n" if docstring is None else docstring
7574
function_body = "" if function_body is None else function_body
7675
self._builtins = {} if builtins is None else builtins
7776
super().__init__(
@@ -152,9 +151,9 @@ def function_parameters_name(self) -> List[str]:
152151
return self.function_parameters.replace(",", "").split(" ")
153152

154153
@staticmethod
155-
def get_docstring(function: types.FunctionType) -> str:
154+
def get_docstring(function: types.FunctionType) -> str | None:
156155
docstring = function.__doc__
157-
return "" if docstring is None else textwrap.dedent(docstring)
156+
return None if docstring is None else textwrap.dedent(docstring)
158157

159158
@staticmethod
160159
def _get_function_source_and_def(

tests/test_code.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def test_get_function_paramaters(self):
6969
assert CodeInput.get_function_parameters(self.mock_function_7) == "x, **kwargs"
7070

7171
def test_get_docstring(self):
72+
assert CodeInput.get_docstring(self.mock_function_0) is None
7273
assert (
7374
CodeInput.get_docstring(self.mock_function_1)
7475
== "\nThis is an example function.\nIt adds two numbers.\n"

0 commit comments

Comments
 (0)