Apply textwrap.dedent() to task docstrings#66561
Conversation
When using the @task decorator, task documentation can be passed via the function docstring. However, the indentation from the function body was preserved in the UI, making the documentation look unattractive. This change applies textwrap.dedent() to the docstring before setting it as doc_md, which removes the common leading whitespace from each line. Fixes apache#66477
|
|
||
| from airflow.sdk import dag, task | ||
|
|
||
|
|
There was a problem hiding this comment.
Test coverage is solid. One additional edge case that may be worth covering is an already-dedented docstring to verify the transformation is effectively a no-op when no common indentation exists. Right now the tests only cover indented inputs.
…ing newlines textwrap.dedent preserves leading/trailing newlines from docstrings. Adding .strip() ensures the doc_md is clean without leading/trailing whitespace.
|
Good catch on the test — the CI failure shows that |
Addresses reviewer feedback: adds edge case test verifying that textwrap.dedent is effectively a no-op when docstrings have no common leading whitespace.
|
Thanks for the suggestion @SameerMesiah97! I've added a test case for already-dedented docstrings in the latest push ( |
|
Thanks @SameerMesiah97 for the suggestion! I've already added the already-dedented test case in a previous commit ( |
|
Thanks @SameerMesiah97 — good point about the no-op dedent test. I'll add a test case for an already-dedented docstring to confirm returns the string unchanged when there's no common leading whitespace. |
When using the @task decorator, task documentation can be passed via the function docstring. However, the indentation from the function body was preserved in the UI, making the documentation look unattractive.
This change applies textwrap.dedent() to the docstring before setting it as doc_md, which removes the common leading whitespace from each line.
Fixes #66477
Changes
Testing
Added 4 test cases: