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

fix(assert): Prevent arguments from requiring self #5836

Merged
merged 3 commits into from
Dec 3, 2024

Conversation

omertuc
Copy link
Contributor

@omertuc omertuc commented Dec 3, 2024

It's non-sensical for an argument to require itself, so it must be a mistake, and should be prevented.

This is arguably a breaking change, but of the spacebar heating kind.

Let me know if I should add any tests for this.

@omertuc omertuc changed the title fix(assert): prevent arguments from requiring self fix(assert): Prevent arguments from requiring self Dec 3, 2024
@epage
Copy link
Member

epage commented Dec 3, 2024

Let me know if I should add any tests for this.

Please do.

Generally, we recommend PRs be structured as

  • A test commit where the tests pass, showing the existing behavior
  • A behavior change that updates the test so to continues to pass

This

  • Makes the behavior change obvious to the reviewer and outsiders
  • Helps verify the test

In this case, its going to be a little more obvious, so we might be able to let it slide (in my ideal world, I'd even break out that argument unpacking into its own refactor commit).

@omertuc
Copy link
Contributor Author

omertuc commented Dec 3, 2024

Makes sense, will do that

Use tuple destructuring to make the code clearer

Signed-off-by: Omer Tuchfeld <omer@tuchfeld.dev>
@omertuc omertuc force-pushed the reqself branch 2 times, most recently from e1265ba to 43fd3c0 Compare December 3, 2024 19:01
@omertuc
Copy link
Contributor Author

omertuc commented Dec 3, 2024

Is this what you had in mind?

Add a test that shows that clap doesn't complain when a flag requires
itself.

This test demonstrates existing broken behavior, ideally it should
panic.

It will be fixed in the next commit.

Signed-off-by: Omer Tuchfeld <omer@tuchfeld.dev>
It's non-sensical for an argument to require itself, so it must be a
mistake, and should be prevented.

This is arguably a breaking change, but of the spacebar heating kind.

Signed-off-by: Omer Tuchfeld <omer@tuchfeld.dev>
@epage
Copy link
Member

epage commented Dec 3, 2024

Thanks! Small commits like that make things very easy to review!

@epage epage merged commit 18a81c4 into clap-rs:master Dec 3, 2024
25 checks passed
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

Successfully merging this pull request may close these issues.

2 participants