Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support display no docstring #93

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ 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
Loading