Skip to content

Bug, Unhandled case when a section is empty #160

Closed
@jspaezp

Description

@jspaezp

Issue

# >>> Call Args:  ['tests/data/format/numpydoc/numpydoc_parameter_spacing.py', '--style', 'numpydoc', '--style', 'pep257']

This call fails with an index error because section[0] has length 0, therefore section[0][0] returns an index error.

Fix

Modifying:

# Check that indent on first line of section didn't get weird
first_section = True
for section in new_sections.values():
if first_section:
section[0] = section[0].lstrip()
first_section = False
elif not section[0][0].isspace():
section[0] = f"{' ' * indent_length:s}{section[0]:s}"

To:

 # Check that indent on first line of section didn't get weird 
 first_section = True 
 for section in new_sections.values(): 
     if first_section: 
         section[0] = section[0].lstrip() 
         first_section = False 
     elif len(section[0]) > 0 and not section[0][0].isspace(): # <<<<<< this is the fix
         section[0] = f"{' ' * indent_length:s}{section[0]:s}" 

Related:

Breaking call:

# >>> Call Args:  ['tests/data/format/summary_splitter/regression_151.py', '--style', 'numpydoc', '--linewrap-full-docstring']

Fix:

summary_lines = summary.splitlines()
new_summary = "\n".join(
textwrap.wrap(
summary_lines[0],
width=line_length,
initial_indent=" " * (indent_length + quotes_length),
subsequent_indent=" " * indent_length,
replace_whitespace=True,
)
)[indent_length + quotes_length :]

        summary_lines = summary.splitlines()

        # Here is the fix, checks if the summary line is empty before going though
        if len(summary_lines) == 0:
            summary_lines = [""]

        new_summary = "\n".join(
            textwrap.wrap(
                summary_lines[0],
                width=line_length,
                initial_indent=" " * (indent_length + quotes_length),
                subsequent_indent=" " * indent_length,
                replace_whitespace=True,
            )
        )[indent_length + quotes_length :]


Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions