Skip to content

Py-SDK: More kw-args#11384

Merged
emilk merged 19 commits intomainfrom
emilk/more-kw-args
Oct 2, 2025
Merged

Py-SDK: More kw-args#11384
emilk merged 19 commits intomainfrom
emilk/more-kw-args

Conversation

@emilk
Copy link
Member

@emilk emilk commented Sep 30, 2025

Using a lot of positional arguments have many downsides. One is readability, the other is future-proofing. If we want the ability to change our interfaces in the future, we need to force users to name the arguments.

I've written a migration guide.

None of our own examples or snippets needed updating, so I believe the impact on users will be rather small.

But this is really on of those "Best time to do it was three years ago, next best time is today"

@github-actions
Copy link

github-actions bot commented Sep 30, 2025

Latest documentation preview deployed successfully.

Result Commit Link
698a397 https://landing-migaluxxi-rerun.vercel.app/docs

Note: This comment is updated whenever you push a commit.

@github-actions
Copy link

github-actions bot commented Sep 30, 2025

Web viewer built successfully.

Result Commit Link Manifest
698a397 https://rerun.io/viewer/pr/11384 +nightly +main

Note: This comment is updated whenever you push a commit.

@emilk emilk changed the title Py-SDK: Force kw-args on optional parts of ImageFormat Py-SDK: Use more kw-args when there are a lot of parameters Sep 30, 2025
@emilk emilk changed the title Py-SDK: Use more kw-args when there are a lot of parameters Py-SDK: More kw-args Sep 30, 2025
Copy link
Member

@oxkitsune oxkitsune left a comment

Choose a reason for hiding this comment

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

LGTM!

Very nice improvement!

Copy link
Member

@ntjohnson1 ntjohnson1 left a comment

Choose a reason for hiding this comment

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

I'm a little on the fence here so excuse the verbose post (accompanied by the approval since I don't think there is anything WRONG here).

  1. This probably will break lots of people's (and our own external repos)
  2. I don't generally see this pattern of * to explicitly force people to switch to kwargs but it's not totally bizarre
  3. I think the hope of PLR0917 is to reduce the total number of arguments and that this is an intermediate step to PLR0913
  4. I wonder if varying between 1 and 3 positional args will be weird to people, I guess if we choose the right args to expose should be fine

I definitely don't want KWARGS only but this is probably a reasonable compromise. PLR0913 is probably a much larger refactor but if we are feeling adventurous we could try enabling it, exclude all current offenders and hope its existence prevents future argument sprawl.

Copy link
Member

@timsaucer timsaucer left a comment

Choose a reason for hiding this comment

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

From a code correctness perspective this looks good.

There is a separate question of whether it's the right thing to do since it impacting so many user facing APIs.

That being said, the updates on their side may be a tad annoying but are each individually straigh forward.

Comment on lines +2469 to +2474
if 2 < required.len() {
// There's a lot of required arguments.
// Using positional arguments would make usage hard to read.
// better for force kw-args for ALL arguments:
chain!(std::iter::once("*".to_owned()), required, optional).collect()
} else if optional.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this is going to set all arguments to kw-args if number of required args is 3 or more but down in the ruff rules we have max-positional-args = 3. So is 3 allowable or do you want to intentionally be more restrictive here or did I miss something about how this bit works?

Copy link
Member

Choose a reason for hiding this comment

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

Does self count as one?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to be more restrictive here, at least for now. We seem to have no archetypes with exactly three required fields, so it doesn't matter much in practice for now. I rather start restrictive and expand later (removing a * is never a breaking change).

Copy link
Member Author

Choose a reason for hiding this comment

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

No, self is not counted.

@emilk emilk merged commit 296a574 into main Oct 2, 2025
47 checks passed
@emilk emilk deleted the emilk/more-kw-args branch October 2, 2025 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants