Skip to content

functions must return parser not parser.parse_args() #55

Open
@dennisbrookner

Description

@dennisbrookner

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions