Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dennisbrookner opened this issue Jan 3, 2023 · 1 comment
Open

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

dennisbrookner opened this issue Jan 3, 2023 · 1 comment

Comments

@dennisbrookner
Copy link

dennisbrookner commented Jan 3, 2023

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!

@langston-barrett
Copy link
Collaborator

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

Sure, sounds good! Thanks!

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

No branches or pull requests

2 participants