Skip to content

Commit

Permalink
Support display no docstring
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agoscinski committed Dec 17, 2024
1 parent 99a24f6 commit efeb1d1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
dependencies = [
"ipywidgets>=8.0.0",
"numpy<2.0.0",
"widget_code_input>=4.0.13",
"widget_code_input @ git+https://github.com/agoscinski/widget-code-input@remove-docstring",
"matplotlib",
"termcolor"
]
Expand Down
5 changes: 2 additions & 3 deletions src/scwidgets/code/_widget_code_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def __init__(
if function_name is None:
raise ValueError("function_name must be given if no function is given.")
function_parameters = "" if function_parameters is None else function_parameters
docstring = "\n" if docstring is None else docstring
function_body = "" if function_body is None else function_body
self._builtins = {} if builtins is None else builtins
super().__init__(
Expand Down Expand Up @@ -152,9 +151,9 @@ def function_parameters_name(self) -> List[str]:
return self.function_parameters.replace(",", "").split(" ")

@staticmethod
def get_docstring(function: types.FunctionType) -> str:
def get_docstring(function: types.FunctionType) -> str | None:
docstring = function.__doc__
return "" if docstring is None else textwrap.dedent(docstring)
return None if docstring is None else textwrap.dedent(docstring)

@staticmethod
def _get_function_source_and_def(
Expand Down
3 changes: 3 additions & 0 deletions tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def test_get_function_paramaters(self):
assert CodeInput.get_function_parameters(self.mock_function_7) == "x, **kwargs"

def test_get_docstring(self):
assert (
CodeInput.get_docstring(self.mock_function_0) is None
)
assert (
CodeInput.get_docstring(self.mock_function_1)
== "\nThis is an example function.\nIt adds two numbers.\n"
Expand Down

0 comments on commit efeb1d1

Please sign in to comment.