Skip to content

Conversation

@matt-hayden
Copy link

@matt-hayden matt-hayden commented Aug 17, 2020

Hello,

Invoke v1.5.0 on Python 2.7. Methods defined without a docstring, or with an empty docstring, cause an exception at .splitlines()[0]. This doesn't cause a problem running the subcommands themselves, but --list fails.

Example: run fab --list with this:

import fabric

@fabric.tasks.task
def foo(ctx):
    """
    """
    print("noop")

@matt-hayden
Copy link
Author

@bitprophet , is this worth keeping open?

@jefftriplett jefftriplett requested a review from bitprophet May 13, 2021 23:57
Copy link

@jefftriplett jefftriplett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will defer to @bitprophet, but it seems like a reasonable edge-case.

return None
return docstring.lstrip().splitlines()[0]
lines = docstring.lstrip().splitlines()
return lines[0] if lines else ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bitprophet would you prefer this return None?

@bitprophet bitprophet closed this in 575bd70 Jun 6, 2021
@bitprophet
Copy link
Member

Thanks for noticing this! I ended up making my own commit:

  • IMO the "right" fix here is to try a strip() on the docstring in the early test; this lets us always return either None-or-string (as Jeff T noted). Bit less code, bit cleaner/more obvious.
  • The docstring of this method (ironically) was inaccurate re: that issue (None vs empty string) so I also updated it
  • Changelog entry
  • Committed to release branch and merged to main branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants