Skip to content

Always list all positional arguments - #3860

Open
kdeldycke wants to merge 2 commits into
pallets:stablefrom
kdeldycke:list-all-positional-arguments
Open

Always list all positional arguments#3860
kdeldycke wants to merge 2 commits into
pallets:stablefrom
kdeldycke:list-all-positional-arguments

Conversation

@kdeldycke

@kdeldycke kdeldycke commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

This is inconsistent with the way options are displayed, as every options are displayed including those without help.

The reason to display all arguments in the Positional arguments section is to not introduce subtle confusion, as an argument without help would only be noticeable in the usage line.

Cloup already renders the section this way (see janluke/cloup#210) and is the source discussion with @janluke for that bug fix.

In this implementation, I refrained to always display the Positional arguments section. So I made the decision to not print the Positional arguments section in full if and only if at least one of its argument has an help. This decision is open to discussion.

This is a follow up on #3473

@kdeldycke kdeldycke added the help output Help text formatting, layout, and --help rendering label Sep 9, 2026
@kdeldycke kdeldycke added this to the 8.5.1 milestone Sep 9, 2026
@kdeldycke
kdeldycke force-pushed the list-all-positional-arguments branch from 67ed980 to 28c7ae0 Compare September 9, 2026 09:32

@janluke janluke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Of course, I approve the change in behavior, since that's what I decided for Cloup as well.

The code looks correct, but I think we should consider changing get_help_record to always return a tuple (never None; unless this turns useful elsewhere):

    def get_help_record(self, ctx: Context) -> tuple[str, str]:
        return self.make_metavar(ctx), self.help or ""

Returning None when help is None is only hurting us now.

Also, this might read a bit more Pythonic:

    def format_arguments(self, ctx: Context, formatter: HelpFormatter) -> 
        args = [
            param
            for param in self.get_params(ctx)
            if isinstance(param, Argument)
        ]
        if any(arg.help for arg in args):
            # assuming arg.get_help_record() always returns a help re
            help_records = [arg.get_help_record(ctx) for arg in args]
            ...

@kdeldycke
kdeldycke force-pushed the list-all-positional-arguments branch from 28c7ae0 to 0698ea4 Compare September 10, 2026 08:11
@kdeldycke

Copy link
Copy Markdown
Collaborator Author

Of course, I approve the change in behavior, since that's what I decided for Cloup as well.

The code looks correct, but I think we should consider changing get_help_record to always return a tuple (never None; unless this turns useful elsewhere):

    def get_help_record(self, ctx: Context) -> tuple[str, str]:
        return self.make_metavar(ctx), self.help or ""

Returning None when help is None is only hurting us now.

The reason for keeping get_help_record returning tuple[str, str] | None is to keep the Parameter, Option and Argument classes aligned.

I propose to evaluate this change in another PR as this opened a related issue I just stumbled upon. I will open a new one today and ping you there for feedback. Let's keep this PR focused on Positional arguments behavior for now.

Also, this might read a bit more Pythonic:

    def format_arguments(self, ctx: Context, formatter: HelpFormatter) -> 
        args = [
            param
            for param in self.get_params(ctx)
            if isinstance(param, Argument)
        ]
        if any(arg.help for arg in args):
            # assuming arg.get_help_record() always returns a help re
            help_records = [arg.get_help_record(ctx) for arg in args]
            ...

Good point. Just applied your changes.

@kdeldycke

Copy link
Copy Markdown
Collaborator Author

Returning None when help is None is only hurting us now.

The reason for keeping get_help_record returning tuple[str, str] | None is to keep the Parameter, Option and Argument classes aligned.

I propose to evaluate this change in another PR as this opened a related issue I just stumbled upon. I will open a new one today and ping you there for feedback. Let's keep this PR focused on Positional arguments behavior for now.

OK I get it now. You are right, this change should be bundled in this PR, as it highlight the policy of refusing to allow an argument to be hidden. Just made the changes.

This PR is ready to be reviewed.

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

Labels

help output Help text formatting, layout, and --help rendering

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants