sphinx-contrib / sphinx-contrib/autoprogram

functions must return `parser` not `parser.parse_args()`

Open
#55 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
48
Forks
24
Avg merge
2h 15m
Merged PRs (30d)
1

Description

Hey, thanks for a great package!! I don't think the below is a huge issue, but I just spent a few hours debugging it, so I figured I would pass it along.

In my understanding, there are two, roughly equivalent ways one might structure their argparse usage. I won't opine on the relative benefits, only that I've seen both in the wild.

method 1:

def parse_arguments():
    parser = argparse.ArgumentParser()
    # blah blah blah
    return parser

def main():
    parser = parse_arguments()
    args = parser.parse_args()

method 2:

def parse_arguments():
    parser = argparse.ArgumentParser()
    # blah blah blah
    return parser.parse_args()

def main():
    args = parse_arguments()

Method 1 works with autoprogram, and is what is outlined in the docs. However, method 2 doesn't work, and actually raises a pretty unhelpful error message. I don't think there's any reason to support method 2, and I could imagine that would be a headache to implement anyway. But, I think it might be possible to detect that a user has done this and raise a helpful error, or even simpler, add a clarifying sentence or two in the docs. (Or even simpler, just leave this issue open for others to find!)

With blessing, I'd be happy to take a stab at editing the docs accordingly. Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the documentation describing autoprogram and the parse_arguments pattern. Clarify that the function must return the argparse parser rather than parser.parse_args(), and distinguish the two usage methods shown in the issue. Done means the documented requirement is unambiguous and users are less likely to encounter the unhelpful error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.