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

Question: Can no-cover "cover" the rest of the function? #1741

Open
stdedos opened this issue Jan 30, 2024 · 2 comments
Open

Question: Can no-cover "cover" the rest of the function? #1741

stdedos opened this issue Jan 30, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@stdedos
Copy link

stdedos commented Jan 30, 2024

Is your feature request related to a problem? Please describe.

I have the end of the main() function like so:

    ...

    if args.command == Commands.CMD.value:
        return cmd_handler(j, args)
    
    print(f"Either command '{args.command}' was not handled, or the end of the world is coming!\n", file=sys.stderr)
    parser.print_help(file=sys.stderr)

    return os.EX_USAGE

I'd like to ignore it with a no-cover.

Basically, the rest of the function would be hard to hit (somehow argparse does not "match" command with its function, or dev forgets to return cmd_handler().

I'd like to avoid the if return else pattern since, on top of that, I agree with the https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/no-else-return.html check aesthetically

Any solutions I missed?

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context about the feature request here.

@stdedos stdedos added enhancement New feature or request needs triage labels Jan 30, 2024
@nedbat
Copy link
Owner

nedbat commented Jan 30, 2024

Currently there is not a pragma comment that means "ignore the rest of this." The simplest approach that you haven't mentioned is to put that tail of the function into a new function, then you can pragma the call and the function definition with one comment each. It will still look a bit odd though.

@stdedos
Copy link
Author

stdedos commented Jan 30, 2024

Oh yeah - something like def handle_unexpected_main_fallthrough(cmd): # pragma: no-cover

... ofc that will still need the return handle_unexpected_main_fallthrough(cmd), I guess.
But better than nothing, or throwing some "known ignored exception" I guess.

I can go with that. Thank you for the idea 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants