Skip to content

AttributeError in make_default_short_help(None) #3189

@davchaudhari

Description

@davchaudhari

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:

  1. Return an empty string ("") when passed None, OR
  2. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions