Skip to content

AttributeError in make_default_short_help(None) #3189

Closed as not planned
Closed as not planned

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)

Activity

  1. davidism commented on Jan 20, 2026

    @davidism
    Member

    Please do not use LLMs to generate bug reports for you.

    That's why it's annotated to take str, not str | None. Use a type checker. Additionally, this is not a public API, so we make no guarantees about its availability or use.

  2. locked as resolved and limited conversation to collaborators on Feb 4, 2026
  3. added
    rejected AI
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    rejected AI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions