Bug Description
click.utils.make_default_short_help() crashes with AttributeError when passed None. This can occur when programmatically creating commands where help text might not be provided, or when a developer passes None expecting the function to handle it gracefully.
Reproduction
from click.utils import make_default_short_help
# This crashes
result = make_default_short_help(None)
Full traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "click/utils.py", line 62, in make_default_short_help
paragraph_end = help.find("\n\n")
^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'find'
Real-world scenario where this could happen:
@click.command()
@click.option('--help-text', default=None)
def my_command(help_text):
# If help_text is None, this crashes
short_help = make_default_short_help(help_text)
Expected Behavior
The function should either:
- Return an empty string (
"") when passed None, OR
- Raise a clear
TypeError with a message like "help must be a string, not NoneType"
Currently, the AttributeError doesn't clearly indicate that the problem is with the input validation.
Suggested Fix
Add input validation at the start of the function:
def make_default_short_help(help: str | None, max_length: int = 45) -> str:
if help is None:
return ""
# ... rest of function
Environment:
- Python version: 3.13.1
- Click version: latest from main branch (tested with git clone)
Bug Description
click.utils.make_default_short_help()crashes withAttributeErrorwhen passedNone. This can occur when programmatically creating commands where help text might not be provided, or when a developer passesNoneexpecting the function to handle it gracefully.Reproduction
Full traceback:
Real-world scenario where this could happen:
Expected Behavior
The function should either:
"") when passedNone, ORTypeErrorwith a message like"help must be a string, not NoneType"Currently, the
AttributeErrordoesn't clearly indicate that the problem is with the input validation.Suggested Fix
Add input validation at the start of the function:
Environment: