docs: show beta directive (#25013)

![Screenshot 2024-08-02 at 7 15 34
PM](https://github.com/user-attachments/assets/086831c7-36f3-4962-98dc-d707b6289747)
This commit is contained in:
Bagatur
2024-08-02 20:07:45 -07:00
committed by GitHub
parent e81ddb32a6
commit 1dcee68cb8
4 changed files with 38 additions and 29 deletions

View File

@@ -212,25 +212,10 @@ def beta(
wrapper.__doc__ = new_doc
return cast(T, wrapper)
old_doc = inspect.cleandoc(old_doc or "").strip("\n")
# old_doc can be None
if not old_doc:
old_doc = ""
# Modify the docstring to include a beta notice.
notes_header = "\nNotes\n-----"
components = [
message,
addendum,
]
old_doc = inspect.cleandoc(old_doc or "").strip("\n") or ""
components = [message, addendum]
details = " ".join([component.strip() for component in components if component])
new_doc = (
f"[*Beta*] {old_doc}\n"
f"{notes_header if notes_header not in old_doc else ''}\n"
f".. beta::\n"
f" {details}"
)
new_doc = f".. beta::\n" f" {details}\n\n" f"{old_doc}\n"
if inspect.iscoroutinefunction(obj):
finalized = finalize(awarning_emitting_wrapper, new_doc)

View File

@@ -114,7 +114,7 @@ def test_beta_function() -> None:
doc = beta_function.__doc__
assert isinstance(doc, str)
assert doc.startswith("[*Beta*] original doc")
assert doc.startswith(".. beta::")
assert not inspect.iscoroutinefunction(beta_function)
@@ -134,7 +134,7 @@ async def test_beta_async_function() -> None:
doc = beta_function.__doc__
assert isinstance(doc, str)
assert doc.startswith("[*Beta*] original doc")
assert doc.startswith(".. beta::")
assert inspect.iscoroutinefunction(beta_async_function)
@@ -155,7 +155,7 @@ def test_beta_method() -> None:
doc = obj.beta_method.__doc__
assert isinstance(doc, str)
assert doc.startswith("[*Beta*] original doc")
assert doc.startswith(".. beta::")
assert not inspect.iscoroutinefunction(obj.beta_method)
@@ -176,7 +176,7 @@ async def test_beta_async_method() -> None:
doc = obj.beta_method.__doc__
assert isinstance(doc, str)
assert doc.startswith("[*Beta*] original doc")
assert doc.startswith(".. beta::")
assert inspect.iscoroutinefunction(obj.beta_async_method)
@@ -195,7 +195,7 @@ def test_beta_classmethod() -> None:
doc = ClassWithBetaMethods.beta_classmethod.__doc__
assert isinstance(doc, str)
assert doc.startswith("[*Beta*] original doc")
assert doc.startswith(".. beta::")
def test_beta_staticmethod() -> None:
@@ -214,7 +214,7 @@ def test_beta_staticmethod() -> None:
)
doc = ClassWithBetaMethods.beta_staticmethod.__doc__
assert isinstance(doc, str)
assert doc.startswith("[*Beta*] original doc")
assert doc.startswith(".. beta::")
def test_beta_property() -> None:
@@ -234,7 +234,7 @@ def test_beta_property() -> None:
)
doc = ClassWithBetaMethods.beta_property.__doc__
assert isinstance(doc, str)
assert doc.startswith("[*Beta*] original doc")
assert doc.startswith(".. beta::")
def test_whole_class_beta() -> None:
@@ -277,7 +277,7 @@ def test_whole_class_inherited_beta() -> None:
"""Test whole class beta status for inherited class.
The original version of beta decorator created duplicates with
'[*Beta*]'.
'.. beta::'.
"""
# Test whole class beta status
@@ -339,9 +339,9 @@ def test_whole_class_inherited_beta() -> None:
"the API may change."
)
# if [*Beta*] was inserted only once:
# if .. beta:: was inserted only once:
if obj.__doc__ is not None:
assert obj.__doc__.count("[*Beta*]") == 1
assert obj.__doc__.count(".. beta::") == 1
# Tests with pydantic models
@@ -368,4 +368,4 @@ def test_beta_method_pydantic() -> None:
doc = obj.beta_method.__doc__
assert isinstance(doc, str)
assert doc.startswith("[*Beta*] original doc")
assert doc.startswith(".. beta::")