From ca00840f5949a61e1ffc9ea9c647fa83a9315c7e Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 26 Sep 2023 09:44:44 +0200 Subject: [PATCH 1/2] Add test to show help strings for other trait types I've obseved that Dict, List, Instance, and Command trait types no longer gets their help strings set with traitlets 5.10.0 but this wasn't an issue in traitlets 5.9.0. --- tests/docs/sample_module.py | 67 +++++++++++++++++++++++++++- tests/docs/source/autotrait/help.rst | 15 +++++++ tests/test_autodoc_traits.py | 6 +++ 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/tests/docs/sample_module.py b/tests/docs/sample_module.py index 3738b24..c7c933f 100644 --- a/tests/docs/sample_module.py +++ b/tests/docs/sample_module.py @@ -5,7 +5,7 @@ autodoc_traits against. It does not contain tests. """ -from traitlets import Bool +from traitlets import Bool, Dict, Instance, Integer, Unicode, Union from traitlets.config.configurable import Configurable @@ -81,3 +81,68 @@ def subclass_non_trait_property(self): def subclass_method(self): """subclass_method docstring""" + + +class TraitTypesSampleConfigurable(Configurable): + """TraitTypesSampleConfigurable docstring""" + + trait_integer = Integer( + help="""trait_integer help text""", + config=True, + ) + trait_integer_nohelp = Integer( + config=True, + ) + trait_integer_noconfig = Integer( + help="""trait_integer_noconfig help text""", + ) + + trait_unicode = Unicode( + help="""trait_unicode help text""", + config=True, + ) + trait_unicode_nohelp = Unicode( + config=True, + ) + trait_unicode_noconfig = Unicode( + help="""trait_unicode_noconfig help text""", + ) + + trait_dict = Dict( + help="""trait_dict help text""", + config=True, + ) + trait_dict_nohelp = Dict( + config=True, + ) + trait_dict_noconfig = Dict( + help="""trait_dict_noconfig help text""", + ) + + trait_instance = Instance( + klass=SampleConfigurable, + help="""trait_instance help text""", + config=True, + ) + trait_instance_nohelp = Instance( + klass=SampleConfigurable, + config=True, + ) + trait_instance_noconfig = Instance( + klass=SampleConfigurable, + help="""trait_instance_noconfig help text""", + ) + + trait_union = Union( + [Integer(), Unicode()], + help="""trait_union help text""", + config=True, + ) + trait_union_nohelp = Union( + [Integer(), Unicode()], + config=True, + ) + trait_union_noconfig = Union( + [Integer(), Unicode()], + help="""trait_union_noconfig help text""", + ) diff --git a/tests/docs/source/autotrait/help.rst b/tests/docs/source/autotrait/help.rst index be5e876..8181b99 100644 --- a/tests/docs/source/autotrait/help.rst +++ b/tests/docs/source/autotrait/help.rst @@ -5,3 +5,18 @@ Test that we present the trait's provided ``help``. .. autotrait:: sample_module.SampleConfigurable.trait :noindex: + +.. autotrait:: sample_module.TraitTypesSampleConfigurable.trait_integer + :noindex: + +.. autotrait:: sample_module.TraitTypesSampleConfigurable.trait_unicode + :noindex: + +.. autotrait:: sample_module.TraitTypesSampleConfigurable.trait_dict + :noindex: + +.. autotrait:: sample_module.TraitTypesSampleConfigurable.trait_instance + :noindex: + +.. autotrait:: sample_module.TraitTypesSampleConfigurable.trait_union + :noindex: diff --git a/tests/test_autodoc_traits.py b/tests/test_autodoc_traits.py index 7018f46..063d6f5 100644 --- a/tests/test_autodoc_traits.py +++ b/tests/test_autodoc_traits.py @@ -99,6 +99,7 @@ def test_sphinx_build_all_docs(temp_docs_dir, monkeypatch): "SampleConfigurableSubclass docstring", "SampleNonConfigurable docstring", "SampleNonConfigurableSubclass docstring", + "TraitTypesSampleConfigurable docstring", ], [], ), @@ -107,6 +108,11 @@ def test_sphinx_build_all_docs(temp_docs_dir, monkeypatch): [ "c.SampleConfigurable.trait", "trait help text", + "trait_integer help text", + "trait_unicode help text", + "trait_dict help text", + "trait_instance help text", + "trait_union help text", ], [], ), From 8c611c51fbe535e04c36edfe85e77f2b73b31d5b Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Wed, 27 Sep 2023 12:27:39 +0200 Subject: [PATCH 2/2] Add upper bound on traitlets, <5.10 --- pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f0d5357..6d263a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,9 @@ dynamic = ["version"] requires-python = ">=3.7" dependencies = [ "sphinx>=4", - "traitlets>=4", + # FIXME: traitlets are upper bounded as a workaround to + # https://github.com/jupyterhub/autodoc-traits/issues/55 + "traitlets>=4,<5.10", ] [project.optional-dependencies]